Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 1.25 KB

readme.md

File metadata and controls

62 lines (46 loc) · 1.25 KB

Hash Table Api

// Time Complexity: O(1)
length: number

// *generator function, it returens an iterator.
iterator(): Generator

// Time Complexity: 
//  average cases: O(1)
//  wrost case: O(n)
add(data: DataType<any>): boolean

// Time Complexity: 
//  average cases: O(1)
//  wrost case: O(n)
remove(key: string): boolean|any[]

// Time Complexity: 
//  average cases: O(1)
//  wrost case: O(n)
update(key: string, newValue: DataType<any>): boolean|DataType<any>

// Time Complexity: 
//  average cases: O(1)
//  wrost case: O(n)
get(key: string): boolean|DataType<any>

// Time Complexity: O(n)
log(column: string[]): void,


Example

import { HashTable } from "https://deno.land/x/datastructure/mod.ts";

const hashTable = new HashTable()

hashTable.add({key: "abm", value: "Sourav"})
hashTable.add({key: "apple", value: {company: "Apple Inc"}})
hashTable.add({key: "arr", value: [1, 2, 3]})

hashTable.remove("arr");

const iterator = hashTable.iterator()
let iteratorNext = iterator.next()
// console.log(iteratorNext.next(), iteratorNext.next());
while (iteratorNext.done === false) {
	console.log(iteratorNext.value);
	iteratorNext = iterator.next()
}

hashTable.get('abm')

hashTable.update('abm', {name: 'AbmSourav'})

hashTable.log()