/// <summary> /// Creates a new dictionary to store and search for deBruijin Nodes /// </summary> public KmerDictionary() { ulong maxSize = (ulong)Math.Pow(2, hashLength); //now create a list of buckets up to that size buckets = new BinaryTreeOfDebruijnNodes[maxSize]; //Create a new tree in each bucket position Enumerable.Range(0, (int)maxSize).ForEach(x => buckets[x] = new BinaryTreeOfDebruijnNodes()); //now make a mask for incoming bits hashingMask = maxSize - 1; //This should be all bits up to the length of the buckets array. }
/// <summary> /// Either returns the DeBrujin node associated with the ulong, or /// sets it if an old one does not exist /// /// Parallel Note: Is thread safe /// </summary> /// <returns>The node representing this value</returns> public DeBruijnNode SetNewOrGetOld(KmerData32 value, bool makeNewIfNotFound = true) { int bucket = assignBucket(value); BinaryTreeOfDebruijnNodes curBucket = buckets[bucket]; //keep it thread safe for additions DeBruijnNode toReturn; lock (curBucket) { toReturn = curBucket.AddOrReturnCurrent(value, makeNewIfNotFound); } return(toReturn); }