Abstract result sets beind a Node_list interface.
[tatoo.git] / src / naive_node_list.ml
diff --git a/src/naive_node_list.ml b/src/naive_node_list.ml
new file mode 100644 (file)
index 0000000..c148732
--- /dev/null
@@ -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 }