From: Jean-Christophe Beaupré Date: Sat, 20 Dec 2014 19:24:57 +0000 (-0500) Subject: neo4j/graph: Implement optimization services of `SequentialNodeCollection`. X-Git-Tag: v0.7.1~38^2~2 X-Git-Url: http://nitlanguage.org neo4j/graph: Implement optimization services of `SequentialNodeCollection`. Signed-off-by: Jean-Christophe Beaupré --- diff --git a/lib/neo4j/graph/sequential_id.nit b/lib/neo4j/graph/sequential_id.nit index 0bcaa6c..fb6129f 100644 --- a/lib/neo4j/graph/sequential_id.nit +++ b/lib/neo4j/graph/sequential_id.nit @@ -37,6 +37,13 @@ private import pipeline # assert c["id"] == 4 # assert nodes.to_a == [a, b, c] # assert nodes.length == 3 +# +# nodes.compact +# assert a["id"] == 1 +# assert b["id"] == 2 +# assert c["id"] == 3 +# assert nodes.to_a == [a, b, c] +# assert nodes.length == 3 # ~~~ class SequentialNodeCollection super NeoNodeCollection @@ -60,6 +67,8 @@ class SequentialNodeCollection return id >= 0 and id < nodes.length and nodes[id] isa NeoNode end + redef fun enlarge(cap) do nodes.enlarge(cap) + redef fun register(node) do nodes.add node id_of(node) = nodes.length @@ -94,4 +103,14 @@ class SequentialNodeCollection nodes.clear length = 0 end + + redef fun compact do + var i = iterator + + nodes = new Array[nullable NeoNode] + for n in i do + nodes.add n + id_of(n) = nodes.length + end + end end