C# Class s1ck.GraphDB.Plugins.Index.BinaryTree.BinaryTreeIndex

This class represents a sample index for the sones GraphDB. It is part of the tutorial on "Custom Indices" which can be found here: http://developers.sones.de/wiki/doku.php?id=documentation:plugins:database:indices The implementation is a binary search tree as it is described here: http://en.wikipedia.org/wiki/Binary_tree The index can be used as 1:1 or 1:n mapping between keys and associated values. It is not designed for production use, there is no concerning about parallel access or persistence. Feel free to use this index as a starting point for own implementations. Author: Martin "s1ck" Junghanns ([email protected])
Inheritance: sones.Plugins.Index.Abstract.ASonesIndex, IPluginable
Datei anzeigen Open project: sones/sones-bstindex-tutorial

Public Methods

Method Description
Add ( IComparable myKey, long myVertexID, IndexAddStrategy myIndexAddStrategy = IndexAddStrategy.MERGE ) : void

Adds a search key and its associated value to the index. If IndexAddStrategy is REPLACE, an existing values associated with the key will be replaced by the new value. If IndexAddStrategy is MERGE, the new value will be added to the existing set. If IndexAddStrategy is UNIQUE, an exception will be thrown if the key already exists.

BinaryTreeIndex ( ) : System

Empty constructor. This one is important for the sones PluginManager.

BinaryTreeIndex ( IList myPropertyIDs ) : System

Initializes the binary tree index and assigns a list of propertyIDs to the internal member.

Clear ( ) : void

Resets the index by setting the root node to null and letting the GC do the work.

ContainsKey ( IComparable myKey ) : bool

Checks if a given key exists in the index.

Dispose ( ) : void

Releases all resources which are hold by the index.

GetKeyType ( ) : Type

Returns the type of the indexed keys. Note: If the index is empty the typeof(IComparable) will be returned.

InitializePlugin ( string UniqueString, object>.Dictionary myParameters = null ) : IPluginable

This method is called by the plugin manager when the plugin is loaded. It loads the indexed propertyIDs out of the parameter dictionary and initializes the index with these propertyIDs

KeyCount ( ) : long

Returns the number of keys stored in the index.

Keys ( ) : IEnumerable

Returns sorted keys stored in the tree.

Optimize ( ) : void

Currently nothing happens here. TODO: maybe some rebalancing

Remove ( IComparable myKey ) : bool

Removes the given key and all associated values from the index.

RemoveRange ( IEnumerable myKeys ) : void

Removes multiple keys from the index

TryGetValues ( IComparable myKey, IEnumerable &myVertexIDs ) : bool

Writes the associated value to the out param if the key exists.

TryRemoveValue ( IComparable myKey, long myValue ) : bool

Checks if a given value is associated with a given key and if yes, the key will be deleted from the index. TODO: this method checks first if key and value exists and then removes it. maybe this can be done in one step by duplicating the remove method.

ValueCount ( ) : long

Returns the number of values stored in the index.

this ( IComparable myKey ) : IEnumerable

Returns the values associated with the given key or throws an Exception if the key does not exist.

Private Methods

Method Description
Add ( BinaryTreeNode myTreeNode, IComparable myKey, System.Int64 myValue, IndexAddStrategy myIndexAddStrategy ) : void

Adds a given search key and the associated value to the index.

Find ( BinaryTreeNode myTreeNode, IComparable myKey ) : BinaryTreeNode

Checks if a given key exists in the tree

FindMinNodeIn ( BinaryTreeNode myTreeNode ) : BinaryTreeNode

Returns the minimum BinaryTreeNode in a subtree. The minimum node is the most left node in the subtree.

Remove ( BinaryTreeNode myTreeNode, IComparable myKey, bool &myRemoved ) : BinaryTreeNode

Removes a given key from the tree, if it exists. Returns the new (or existing) root node.

RemoveMinIn ( BinaryTreeNode myTreeNode ) : BinaryTreeNode

Removes the minium BinaryTreeNode in a tree. The minimum node is the most left node in the subtree.

TraverseInOrder ( BinaryTreeNode myTreeNode, List &myResult ) : void

Traverses the tree in-order: Left-Root-Right This means the keys are returned sorted.

Method Details

Add() public method

Adds a search key and its associated value to the index. If IndexAddStrategy is REPLACE, an existing values associated with the key will be replaced by the new value. If IndexAddStrategy is MERGE, the new value will be added to the existing set. If IndexAddStrategy is UNIQUE, an exception will be thrown if the key already exists.
public Add ( IComparable myKey, long myVertexID, IndexAddStrategy myIndexAddStrategy = IndexAddStrategy.MERGE ) : void
myKey IComparable Search key
myVertexID long Associated value
myIndexAddStrategy IndexAddStrategy Define what happens, if the key already exists.
return void

BinaryTreeIndex() public method

Empty constructor. This one is important for the sones PluginManager.
public BinaryTreeIndex ( ) : System
return System

BinaryTreeIndex() public method

Initializes the binary tree index and assigns a list of propertyIDs to the internal member.
public BinaryTreeIndex ( IList myPropertyIDs ) : System
myPropertyIDs IList A list of indexed propertyIDs
return System

Clear() public method

Resets the index by setting the root node to null and letting the GC do the work.
public Clear ( ) : void
return void

ContainsKey() public method

Checks if a given key exists in the index.
public ContainsKey ( IComparable myKey ) : bool
myKey IComparable Search key
return bool

Dispose() public method

Releases all resources which are hold by the index.
public Dispose ( ) : void
return void

GetKeyType() public method

Returns the type of the indexed keys. Note: If the index is empty the typeof(IComparable) will be returned.
public GetKeyType ( ) : Type
return System.Type

InitializePlugin() public method

This method is called by the plugin manager when the plugin is loaded. It loads the indexed propertyIDs out of the parameter dictionary and initializes the index with these propertyIDs
public InitializePlugin ( string UniqueString, object>.Dictionary myParameters = null ) : IPluginable
UniqueString string
myParameters object>.Dictionary
return IPluginable

KeyCount() public method

Returns the number of keys stored in the index.
public KeyCount ( ) : long
return long

Keys() public method

Returns sorted keys stored in the tree.
public Keys ( ) : IEnumerable
return IEnumerable

Optimize() public method

Currently nothing happens here. TODO: maybe some rebalancing
public Optimize ( ) : void
return void

Remove() public method

Removes the given key and all associated values from the index.
public Remove ( IComparable myKey ) : bool
myKey IComparable Search key
return bool

RemoveRange() public method

Removes multiple keys from the index
public RemoveRange ( IEnumerable myKeys ) : void
myKeys IEnumerable search keys to remove
return void

TryGetValues() public method

Writes the associated value to the out param if the key exists.
public TryGetValues ( IComparable myKey, IEnumerable &myVertexIDs ) : bool
myKey IComparable Search key
myVertexIDs IEnumerable Stores the values (if any exist)
return bool

TryRemoveValue() public method

Checks if a given value is associated with a given key and if yes, the key will be deleted from the index. TODO: this method checks first if key and value exists and then removes it. maybe this can be done in one step by duplicating the remove method.
public TryRemoveValue ( IComparable myKey, long myValue ) : bool
myKey IComparable search key
myValue long associated value
return bool

ValueCount() public method

Returns the number of values stored in the index.
public ValueCount ( ) : long
return long

this() public method

Returns the values associated with the given key or throws an Exception if the key does not exist.
public this ( IComparable myKey ) : IEnumerable
myKey IComparable Search key
return IEnumerable