HashMap

버전 1.0.1 (57.5 KB) 작성자: Derek Black
Pure MATLAB hash map implementation
다운로드 수: 59
업데이트 날짜: 2022/6/7

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

인용 양식

Derek Black (2024). HashMap (https://github.com/bit-dream/matlab-hashmap/releases/tag/v1.0.1), GitHub. 검색됨 .

https://www.mathworks.com/matlabcentral/fileexchange/31272-datahash

MATLAB 릴리스 호환 정보
개발 환경: R2017a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
버전 게시됨 릴리스 정보
1.0.1

See release notes for this release on GitHub: https://github.com/bit-dream/matlab-hashmap/releases/tag/v1.0.1

1.0.0

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.