C# Класс 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])
Наследование: sones.Plugins.Index.Abstract.ASonesIndex, IPluginable
Показать файл Открыть проект

Открытые методы

Метод Описание
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.

Приватные методы

Метод Описание
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.

Описание методов

Add() публичный Метод

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.
Результат void

BinaryTreeIndex() публичный Метод

Empty constructor. This one is important for the sones PluginManager.
public BinaryTreeIndex ( ) : System
Результат System

BinaryTreeIndex() публичный Метод

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
Результат System

Clear() публичный Метод

Resets the index by setting the root node to null and letting the GC do the work.
public Clear ( ) : void
Результат void

ContainsKey() публичный Метод

Checks if a given key exists in the index.
public ContainsKey ( IComparable myKey ) : bool
myKey IComparable Search key
Результат bool

Dispose() публичный Метод

Releases all resources which are hold by the index.
public Dispose ( ) : void
Результат void

GetKeyType() публичный Метод

Returns the type of the indexed keys. Note: If the index is empty the typeof(IComparable) will be returned.
public GetKeyType ( ) : Type
Результат System.Type

InitializePlugin() публичный Метод

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
Результат IPluginable

KeyCount() публичный Метод

Returns the number of keys stored in the index.
public KeyCount ( ) : long
Результат long

Keys() публичный Метод

Returns sorted keys stored in the tree.
public Keys ( ) : IEnumerable
Результат IEnumerable

Optimize() публичный Метод

Currently nothing happens here. TODO: maybe some rebalancing
public Optimize ( ) : void
Результат void

Remove() публичный Метод

Removes the given key and all associated values from the index.
public Remove ( IComparable myKey ) : bool
myKey IComparable Search key
Результат bool

RemoveRange() публичный Метод

Removes multiple keys from the index
public RemoveRange ( IEnumerable myKeys ) : void
myKeys IEnumerable search keys to remove
Результат void

TryGetValues() публичный Метод

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)
Результат bool

TryRemoveValue() публичный Метод

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
Результат bool

ValueCount() публичный Метод

Returns the number of values stored in the index.
public ValueCount ( ) : long
Результат long

this() публичный Метод

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
Результат IEnumerable