/// <summary> /// Create a new bucket collection /// </summary> /// <param name="size">the number of buckets</param> /// <param name="hash">the hashing implementation</param> /// <param name="comparer">the equality comparer implementation</param> public MultiItemBucketCollection(int size, IHashGenerator hash, IKeyEqualityComparer comparer) { this.Capacity = size; this.hash = hash; this.comparer = comparer; Clear(); }
/// <summary> /// Create a new bucket collection /// </summary> /// <param name="size">the number of buckets</param> /// <param name="hash">the hashing implementation</param> /// <param name="comparer">the equality comparer implementation</param> public SingleItemBucketCollection(int size, float load, IHashGenerator hash, IKeyEqualityComparer comparer) { LoadFactor = load; Capacity = size; this.hash = hash; this.comparer = comparer; Clear(); }
/// <summary> /// Makes an empty bucket array /// </summary> /// <param name="size">The number of items in the array</param> /// <param name="comparer">The key equality comparer interface to set in the buckets</param> /// <returns>An IBucket array</returns> private static IBucket[] Clear(int size, IKeyEqualityComparer comparer) { var buckets = (IBucket[])Array.CreateInstance(typeof(TBucket), size); for (var i = 0; i < size; i++) { var val = (IBucket)Activator.CreateInstance(typeof(TBucket), comparer); buckets[i] = val; } return(buckets); }
/// <summary> /// Initializs the hashtable with the provided size /// Initializes provided IHashGenerator and IKeyEqualityComparer Implementations /// </summary> /// <param name="size">the size of the hashtable to initialize</param> /// <param name="keyhash">the IHashGenerator implementation to use</param> /// <param name="comparer">the IKeyEqualityComparer implementation to use</param> public SimpleHashTable(int size, IHashGenerator keyhash, IKeyEqualityComparer comparer) { if (size <= 0 || size > maxSize) { throw new ArgumentOutOfRangeException("Initial size must be within range 0 < size < " + (maxSize + 1)); } if (comparer == null || keyhash == null) { throw new ArgumentNullException("Key comparer and key hash implementations cannot be null"); } buckets = BucketCollectionFactory.MakeBuckets <IMultiItemBucket>(size, keyhash, comparer); }
public KeyValueBucket(IKeyEqualityComparer comparer) { }
public static IBucketCollection MakeBuckets <TBucket>(int length, IHashGenerator hash, IKeyEqualityComparer comparer) where TBucket : IBucket { if (length < 3) { length = 3; } if (typeof(IMultiItemBucket).IsAssignableFrom(typeof(TBucket))) { return(new MultiItemBucketCollection <LinkedListBucket>(length, hash, comparer)); } else if (typeof(ISingleItemBucket).IsAssignableFrom(typeof(TBucket))) { return(new SingleItemBucketCollection <KeyValueBucket>(length, 0.72f, hash, comparer)); } return(null); }
/// <summary> /// A new instance of the Linked List Bucket with provided equality comparer /// </summary> /// <param name="comparer">An IKeyEqualityComparer implementation</param> public LinkedListBucket(IKeyEqualityComparer comparer) => this.comparer = comparer;