projects
/
tatoo.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add two functions to the Node_list interface (and to the naive implementation):
[tatoo.git]
/
src
/
naive_node_list.ml
diff --git
a/src/naive_node_list.ml
b/src/naive_node_list.ml
index
b6f0ae4
..
1b32c47
100644
(file)
--- a/
src/naive_node_list.ml
+++ b/
src/naive_node_list.ml
@@
-41,9
+41,22
@@
let iter f l =
loop l.head
loop l.head
+
+
let length l = l.length
let is_empty l = l.head == nil
let length l = l.length
let is_empty l = l.head == nil
+let pop l =
+ if is_empty l then failwith "pop"
+ else
+ let v = l.head.node in
+ let nhead = l.head.next in
+ l.head <- nhead;
+ if nhead == nil then l.last <- nil;
+ v
+
+
+
let add n l =
let ncell = { node = n;
next = nil }
let add n l =
let ncell = { node = n;
next = nil }
@@
-72,6
+85,15
@@
let push_front n l =
l.length <- l.length + 1;
end
l.length <- l.length + 1;
end
+let append l1 l2 =
+ let len2 = l2.length in
+ if len2 != 0 then begin
+ l1.length <- l1.length + len2;
+ l1.last.next <- l2.head;
+ l1.last <- l2.last;
+ end;
+ l1
+
let head l = l.head
let last l = l.last
let next i = i.next
let head l = l.head
let last l = l.last
let next i = i.next