Giter Club home page Giter Club logo

matlab-hashmap's Introduction

MATLAB HashMap Implementation

Motivation

MATLAB already has a built in class to handle Hash Map/Tables using containers.Map(). However, support for differing data types is limited (optional arguments exist to support differing data types. Some data types are not supported at all (structs, function handles, etc).

This implementation gives you more of a modern implementation of hash maps, allowing mixing of data types, functions/structs/classes as map keys, and concise language to improve code readability.

General

HashMap will auto rehash as new data gets added. Rehash determination is based on number of entries in the map and current number of buckets allocated to the internal array.

A psudo seperate chaining takes place when hash collisions occur (psudo as in not using a more traditional linked list as storage).

Time and space complexity

Look up - Best/Average case O(1), worst case O(N) [when hash function produces key collisions] Space - O(N) array increases linearly with number of dictionary entries

Installation

Double click on the toolbox file (HashMap.mtlbx) or drag the file into the MATLAB command window. This will install the class globally within MATLAB.

Methods

  • get(key) -> get value associated with key
  • set(key,value) -> set new element in map by key and value
  • delete(key) -> delete entry by key
  • has(key) -> Returns true/false based on whether the map contains the key
  • keys() -> returns all keys of map
  • values() -> returns all values of map
  • size - current size of the map (number of keys)

Usage

Empty initialization

map = HashMap(); map.size

size = 0

initialization with data

map = HashMap({'a','b','c'},{1,2,3}); map.size

3

Setting new data

map = HashMap({'a','b','c'},{1,2,3}); map.size

3

map.set('d','4'); map.size

4

has key

map.has('d')

true

get value by key

map.get('d')

4

delete data

map.delete('a'); map.has('a') map.size

false, 3

collect keys

map.keys()

'c' 'b' 'd'

collect values

map.values()

3, 2, 4

matlab-hashmap's People

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.