/// <summary> /// Returns a node for a given k-mer /// </summary> /// <param name="kmer">The kmer</param> /// <returns>true if the item has previously been assigned a serial number; otherwise, false.</returns> public DeBruijnNode TryGetOld(KmerData32 kmer) { int bucketIndex = AssignBucket(kmer); BinaryTreeOfDebrujinNodes tree = _buckets[bucketIndex]; return(tree.SearchTree(kmer)); }
/// <summary> /// Creates a new dictionary to store and search for deBruijin Nodes /// </summary> public KmerDictionary() { var maxSize = (ulong) Math.Pow(2, HashLength); // Create a list of buckets up to that size _buckets = new BinaryTreeOfDebrujinNodes[maxSize]; // Create a new tree in each bucket position Enumerable.Range(0, (int) maxSize).ForEach(x => _buckets[x] = new BinaryTreeOfDebrujinNodes()); // Make a mask for incoming bits _hashingMask = maxSize - 1; // This should be all bits up to the length of the buckets array. }
/// <summary> /// Creates a new dictionary to store and search for deBruijin Nodes /// </summary> public KmerDictionary() { var maxSize = (ulong)Math.Pow(2, HashLength); // Create a list of buckets up to that size _buckets = new BinaryTreeOfDebrujinNodes[maxSize]; // Create a new tree in each bucket position Enumerable.Range(0, (int)maxSize).ForEach(x => _buckets[x] = new BinaryTreeOfDebrujinNodes()); // 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) { int bucket = AssignBucket(value); BinaryTreeOfDebrujinNodes curBucket = _buckets[bucket]; //keep it thread safe for additions DeBruijnNode toReturn; lock (curBucket) { toReturn = curBucket.AddOrReturnCurrent(value); } return(toReturn); }