Sha256: 33e26599a30c2f23f65f64db8083651d3b89ea7a970b3f09d6ec99596b220b6d

Contents?: true

Size: 985 Bytes

Versions: 1

Compression:

Stored size: 985 Bytes

Contents

module DataStructures101

    class ChainedHashTable < Hash::BaseHashTable

        def initialize(capacity = 31, prime = 109345121, hash_lambda = nil)
            super
        end

        private

        def bucket_find(hash_code, key)
            bucket = @table[hash_code]
            return nil if bucket.nil?
            
            bucket.find(key)
        end

        def bucket_insert(hash_code, key, value)
            bucket = @table[hash_code]
            bucket = @table[hash_code] = Hash::Bucket.new if bucket.nil?

            old_size = bucket.size()
            old_value = bucket.insert(key, value)
            @size += (bucket.size - old_size)

            old_value
        end

        def bucket_delete(hash_code, key)
            bucket = @table[hash_code]
            return nil if bucket.nil?

            old_size = bucket.size
            value = bucket.delete(key)
            @size -= (old_size - bucket.size)

            value
        end
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_structures_101-0.2.1 lib/data_structures_101/chained_hash_table.rb