Skip to content

brutalchrist/angular-hashtable

Repository files navigation

angular-hashtable

An HashTable for Angular

API

put(key: K, value: V): HashTable<K, V>

  const table = new HashTable<string, any>();

  table.put('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

get(key: V): V

  const table = new HashTable<string, any>();

  table.put('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  // {msg: "Hello World", emoji: "πŸ›Έ"}
  console.log(table.get('hi'));

getAll(): V[]

  const table = new HashTable<string, any>();

  table.put('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  // [0: {msg: "Hello World", emoji: "πŸ›Έ"}]
  console.log(table.getAll());

getKeys(): string[]

  const table = new HashTable<string, any>();

  table.put('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  // ['hi']
  console.log(table.getKeys());

has(key: K): boolean

  const table = new HashTable<string, any>();

  table.put('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  // true
  console.log(table.has('hi'));

remove(key: K): HashTable<K, V>

  const table = new HashTable<string, any>();

  table.put('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });
  table.remove('hi');

  // []
  console.log(this.table.getAll());

putArray(key: K, value: V): HashTable<K, V>

  const table = new HashTable<string, any>();

  table.putArray('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  table.putArray('hi', {
    msg: 'Hello Space',
    from: '🌎'
  });

getArray(key: K): V

  const table = new HashTable<string, any>();

  table.putArray('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  table.putArray('hi', {
    msg: 'Hello Space',
    from: '🌎'
  });

  // [
  //    0: {msg: "Hello World", emoji: "πŸ›Έ"}
  //    1: {msg: "Hello Space", emoji: "🌍"}
  // ]
  console.log(this.table.getArray('hi'));

removeArray(key: K, value: V): HashTable<K, V>

  const table = new HashTable<string, any>();

  table.putArray('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  table.putArray('hi', {
    msg: 'Hello Space',
    from: '🌎'
  });

  table.remove('hi', 0);

  // [0: {msg: "Hello Space", emoji: "🌍"}]
  console.log(this.table.getArray('hi'));

hasArray(key: K): boolean

  const table = new HashTable<string, any>();

  table.putArray('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  // true
  console.log(this.table.hasArray('hi'));

hasinArray(key: K, value: V): boolean

size(): number

  const table = new HashTable<string, any>();

  table.put('hi', {
    msg: 'Hello World',
    from: 'πŸ›Έ'
  });

  // 1
  console.log(this.table.size());

forEach(callback): void

  const table = new HashTable<string, any>();

  table.put('hi', {
    msg: 'Hello World',
    emoji: 'πŸ›Έ'
  });

  table.putArray('bye', {
    msg: 'Bye World',
    emoji: 'πŸ›Έ'
  });

  table.putArray('bye', {
    msg: 'Bye Space',
    emoji: '🌎'
  });

  // hi => : {msg: "Hello World", emoji: "πŸ›Έ"}
  // bye => : [
  //   0: {msg: "Bye World", emoji: "πŸ›Έ"}
  //   1: {msg: "Bye Space", emoji: "🌎"}
  // ]
  table.forEach((key, value) => {
    console.log(`${key} => :`, value);
  });

Example

import { Component } from '@angular/core';
import { HashTable } from 'angular-hashtable';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  table: HashTable<string, any>;

  constructor() {
    this.table = new HashTable<string, any>();
    this.table.put('hi', {
      msg: 'Hello World',
      from: 'πŸ›Έ'
    });

    if (this.table.has('hi')) {
      console.table(this.table.get('hi'));
    }
  }
}