Class CharArrayNodeDefault
java.lang.Object
com.googlecode.concurrenttrees.radix.node.concrete.chararray.CharArrayNodeDefault
- All Implemented Interfaces:
Node,NodeCharacterProvider,Serializable
A non-optimized implementation of the
Node interface. Stores all variables and supports all behaviours
required by the tree, but not very memory efficient.
See NodeFactory for documentation on how alternative
node implementations can be created to reduce memory overhead. See the Node interface for details on how
to write memory-efficient nodes.
This implementation stores references to child nodes in an AtomicReferenceArray, in ascending sorted order
of the first character of the edges which child nodes define.
The getOutgoingEdge(Character) method uses binary search to locate a requested node, given the first character
of an edge indicated. The node is then read and returned atomically from the AtomicReferenceArray.
The updateOutgoingEdge(com.googlecode.concurrenttrees.radix.node.Node) method ensures that any
attempt to update a reference to a child node preserves the constraints defined in the Node interface. New
child nodes are written atomically to the AtomicReferenceArray.
The constraints defined in the Node interface ensure that the AtomicReferenceArray always remains in
ascending sorted order regardless of modifications performed concurrently, as long as the modifications comply with
the constraints. This node enforces those constraints.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final char[]private final AtomicReferenceArray<Node> private final Object -
Constructor Summary
ConstructorsConstructorDescriptionCharArrayNodeDefault(CharSequence edgeCharSequence, Object value, List<Node> outgoingEdges) -
Method Summary
Modifier and TypeMethodDescriptionReturns all characters of the "edge" encoded in this node, belonging to the connection from a parent node to this node.Returns the first character of the "edge" encoded in this node, belonging to the connection from a parent node to this node.getOutgoingEdge(Character edgeFirstCharacter) Returns the child of this node whose edge starts with the given first character.Returns a read-only list of the child nodes to which this node has outgoing edges, i.e.getValue()Returns a value object which has been associated with a key and which is stored in this node, or returnsnullif no value is stored in this node.toString()voidupdateOutgoingEdge(Node childNode) Updates the child node reference for a given edge (identified by its first character) to point to a different child node.
-
Field Details
-
incomingEdgeCharArray
private final char[] incomingEdgeCharArray -
outgoingEdges
-
outgoingEdgesAsList
-
value
-
-
Constructor Details
-
CharArrayNodeDefault
-
-
Method Details
-
getIncomingEdge
Description copied from interface:NodeReturns all characters of the "edge" encoded in this node, belonging to the connection from a parent node to this node.- Specified by:
getIncomingEdgein interfaceNode- Returns:
- All characters of the "edge" encoded in this node
-
getIncomingEdgeFirstCharacter
Description copied from interface:NodeReturns the first character of the "edge" encoded in this node, belonging to the connection from a parent node to this node.- Specified by:
getIncomingEdgeFirstCharacterin interfaceNode- Specified by:
getIncomingEdgeFirstCharacterin interfaceNodeCharacterProvider- Returns:
- The first character of the "edge" encoded in this node
-
getValue
Description copied from interface:NodeReturns a value object which has been associated with a key and which is stored in this node, or returnsnullif no value is stored in this node. -
getOutgoingEdge
Description copied from interface:NodeReturns the child of this node whose edge starts with the given first character. This read must be performed atomically, in relation to writes made viaNode.updateOutgoingEdge(Node).- Specified by:
getOutgoingEdgein interfaceNode- Parameters:
edgeFirstCharacter- The first character of the edge for which the associated child node is required- Returns:
- The child of this node whose edge starts with the given first character, or
nullif this node has no such outgoing edge
-
updateOutgoingEdge
Description copied from interface:NodeUpdates the child node reference for a given edge (identified by its first character) to point to a different child node. The first character of the given child node's edge must match the first character of an existing outgoing edge from this node. This write must be performed atomically, in relation to reads made viaNode.getOutgoingEdge(Character).- Specified by:
updateOutgoingEdgein interfaceNode- Parameters:
childNode- The new child node to associated with this edge
-
getOutgoingEdges
Description copied from interface:NodeReturns a read-only list of the child nodes to which this node has outgoing edges, i.e. child nodes which have incoming edges from this node. It is intended that this method will be used for copying/cloning nodes.- Specified by:
getOutgoingEdgesin interfaceNode- Returns:
- A read-only list of the child nodes to which this node has outgoing edges
-
toString
-