From 15ba1d74b01e6abe0227086becab1e3517c1f787 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Christophe=20Beaupr=C3=A9?= Date: Sat, 20 Dec 2014 14:24:57 -0500 Subject: [PATCH] neo4j/graph: Implement optimization services of `SequentialNodeCollection`. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jean-Christophe Beaupré --- lib/neo4j/graph/sequential_id.nit | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 -- 1.7.9.5