X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=blobdiff_plain;f=src%2Fnaive_node_list.ml;fp=src%2Fnaive_node_list.ml;h=c14873211347503bd6e6b54fb030a0729d6c0059;hp=0000000000000000000000000000000000000000;hb=3406b26f1ea26a997d7f194c547439891c108ce6;hpb=b6dc15847ef86e61c0d242bc7ae025c1763f8a77 diff --git a/src/naive_node_list.ml b/src/naive_node_list.ml new file mode 100644 index 0000000..c148732 --- /dev/null +++ b/src/naive_node_list.ml @@ -0,0 +1,58 @@ +(***********************************************************************) +(* *) +(* TAToo *) +(* *) +(* Kim Nguyen, LRI UMR8623 *) +(* Université Paris-Sud & CNRS *) +(* *) +(* Copyright 2010-2013 Université Paris-Sud and Centre National de la *) +(* Recherche Scientifique. All rights reserved. This file is *) +(* distributed under the terms of the GNU Lesser General Public *) +(* License, with the special exception on linking described in file *) +(* ../LICENSE. *) +(* *) +(***********************************************************************) + + +type node = Naive_tree.node +type cell = { node : node; + mutable next : cell } + + +type t = { mutable length : int; + mutable head : cell; + mutable last : cell; } + +let rec nil = { node = Naive_tree.nil; + next = nil } + +let create () = { length = 0; + head = nil; + last = nil } + +let iter f l = + let rec loop c = + if c != nil then begin + f c.node; + loop c.next + end + in + loop l.head + + +let length l = l.length + + +let add n l = + let ncell = { node = n; + next = nil } + in + if l.last == nil then + { length = 1; + head = ncell; + last = ncell } + else + let () = l.last.next <- ncell in + { length = l.length + 1; + head = l.head; + last = ncell }