Giter Club home page Giter Club logo

hashmap's Introduction

Hashmap

Two HashMap implementations in Python with two different collision resolution methods: open addressing with quadratic probing and separate chaining.

Dependencies

The HashMap implementation with separate chaining is dependent on the following data structures:

  • LinkedList
  • DynamicArray

The HashMap implementation with open addressing is dependent on the following data structure:

  • DynamicArray
  • HashEntry

All of those data structures are available in the ds.py file. Additionally, it also contains two hash functions required by the HashMap implementation.

Usage

A HashMap can be declared by the following:

m = HashMap(53, hash_function_1)

We can a key-value pair into the HashMap:

m.put('str' + str(100), 250)

We can get the value by key; returns the value if successful, or None if the key is not found.

m.get('str100')   # return 250
m.get('A')        # return None

We can remove the key and its associated value from the HashMap:

m.remove('str100')
m.get('str100')		# return None

Other methods include contains_key(), clear(), empty_buckets(), resize_table(), table_load(), get_keys(), and a standalone find_mode() function. The HashMap implementation with open addressing includes an iterator method to enable the HashMap to iterate across itself.

Class method descriptions:

  • contains_key(): returns True if the given key is in the hash map. False otherwise.
  • clear(): clears the contents of the hash map.
  • empty_buckets(): returns the number of empty buckets in the hash table.
  • resize_table(): changes the capacity of the internal hash table.
  • table_load(): returns the current hash table load factor. The load factor is defined as the ratio of the hash table size to its capacity.
  • get_keys_and_values(): returns a dynamic array where each index contains a tuple of a key/value pair stored in the hash map.

find_mode() is a standalone function that returns a tuple containing, in this order, a dynamic array comprising the mode (most occurring) value/s of the array, and an integer that represents the highest frequency (how many times they appear). This function is impletemented O(n) time complexity.

hashmap's People

Contributors

nelkalm avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.