The local IDs are sequential numbers (integers) starting at 1
.
Note: When loading nodes, the local IDs should forms a mostly contiguous
range starting at 1
. Else, this collection will consume a lot of memory.
Futhermore, the local IDs must be positive.
var nodes = new SequentialNodeCollection("id")
var a = nodes.create_node
var b = new NeoNode
var c = new NeoNode
nodes.register b
c["id"] = 4
nodes.add c
assert a["id"] == 1
assert b["id"] == 2
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
neo4j $ SequentialNodeCollection :: SELF
Type of this instance, automatically specialized in every classneo4j $ SequentialNodeCollection :: compact
Optimize the collection, possibly by rewritting it.neo4j $ SequentialNodeCollection :: enlarge
Enlarge the collection to have at least the specified capacity.neo4j $ SequentialNodeCollection :: get_or_null
Retrieve the node that has the specified local id, or returnnull
.
neo4j $ SequentialNodeCollection :: register
Add the specified node to the graph and set its local ID.neo4j $ SequentialNodeCollection :: remove_at
Remove the node with the specified local ID.core :: Collection :: CONCURRENT
Type of the concurrent variant of this collectionneo4j :: NeoNodeCollection :: _id_property
The property of the nodes that hold the local ID.serialization :: Serializable :: accept_inspect_serializer_core
serialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Collection :: combinations
Allr
-length combinations on self (in same order) without repeated elements.
core :: Collection :: combinations_with_replacement
Allr
-length combination on self (in same order) with repeated elements.
neo4j :: NeoNodeCollection :: compact
Optimize the collection, possibly by rewritting it.serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
neo4j :: NeoNodeCollection :: create_node
Add a new node to the graph and return it.core :: SimpleCollection :: defaultinit
core :: Collection :: defaultinit
core :: Object :: defaultinit
neo4j :: NeoNodeCollection :: enlarge
Enlarge the collection to have at least the specified capacity.serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
neo4j :: NeoNodeCollection :: get_or_null
Retrieve the node that has the specified local id, or returnnull
.
core :: Collection :: has_all
Does the collection contain at least each element ofother
?
core :: Collection :: has_any
Does the collection contain at least one element ofother
?
core :: Collection :: has_exactly
Does the collection contain exactly all the elements ofother
?
neo4j :: NeoNodeCollection :: id_from_jsonable
Convert the specified JSON value into a local ID.neo4j :: NeoNodeCollection :: id_property
The property of the nodes that hold the local ID.neo4j :: NeoNodeCollection :: id_property=
The property of the nodes that hold the local ID.core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).core :: Collection :: permutations
Allr
-length permutations on self (all possible ordering) without repeated elements.
core :: Collection :: product
Cartesian product, overr
times self
.
neo4j :: NeoNodeCollection :: register
Add the specified node to the graph and set its local ID.core :: RemovableCollection :: remove
Remove an occurrence ofitem
core :: RemovableCollection :: remove_all
Remove all occurrences ofitem
neo4j :: NeoNodeCollection :: remove_at
Remove the node with the specified local ID.serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
serialization :: Serializable :: serialize_to_or_delay
Accept references or force direct serialization (usingserialize_to
)
core :: Collection :: serialize_to_pure_json
Utility to serialize a normal Json arraycore :: Collection :: to_concurrent
Wrapsself
in a thread-safe collection
core :: Collection :: to_counter
Create and fill up a counter with the elements of `self.core :: Collection :: to_curlslist
Convert Collection[String] to CURLSListserialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
core :: Collection :: to_shuffle
Return a new array made of elements in a random order.Serializer::serialize
# A Neo4j node collection using a sequential identification scheme.
#
# The local IDs are sequential numbers (integers) starting at `1`.
#
# Note: When loading nodes, the local IDs should forms a mostly contiguous
# range starting at `1`. Else, this collection will consume a lot of memory.
# Futhermore, the local IDs **must** be positive.
#
# ~~~nit
# var nodes = new SequentialNodeCollection("id")
# var a = nodes.create_node
# var b = new NeoNode
# var c = new NeoNode
#
# nodes.register b
# c["id"] = 4
# nodes.add c
# assert a["id"] == 1
# assert b["id"] == 2
# 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
redef type ID_TYPE: Int
private var nodes = new Array[nullable NeoNode]
redef var length = 0
redef fun iterator do return new NullSkipper[NeoNode](self.nodes.iterator)
redef fun [](id) do return nodes[id].as(NeoNode)
redef fun get_or_null(id) do
if id < 0 or id > nodes.length then return null
return nodes[id]
end
redef fun has_id(id) do
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
length += 1
end
redef fun add(node) do
var id = node[id_property]
assert id isa Int else
sys.stderr.write "The local ID must be an `Int`.\n"
end
assert id >= 0 else
sys.stderr.write "The local ID must be greater or equal to 0. Got {id}.\n"
end
# Pad with nulls.
nodes.enlarge(id)
var delta = id - nodes.length
while delta > 0 do
nodes.add null
delta -= 1
end
nodes[id] = node
length += 1
end
redef fun remove_at(id) do
nodes[id] = null
length -= 1
end
redef fun clear do
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
lib/neo4j/graph/sequential_id.nit:18,1--116,3