Module: lib-tde.datastructure.hashmap

Crude implementation of a hashmap

Lua by default already ships a hashmap (called a table) This file is a wrapper for lua's hashmap, intended for people who come from object oriented languages This api provides easy to use functions with which most people are familiar

Time complexity:

  • Lookup element O(n) (worst case) on average O(1)
  • Insert element O(n) (worst case) on average O(1)
  • Remove element O(n) (worst case) on average O(1)
  • update element O(n) (worst case) on average O(1)

Usually the complexity is O(1) unless hash collisions happen then it could be O(x) with a max of O(n)

Info:

  • Copyright: 2020 Tom Meyers
  • Author: Tom Meyers

Static module functions

lib-tde.datastrucuture.hashmap () -> table Create a new hashmap
lib-tde.datastrucuture.hashmap.add (key, value) Add a key value pair to the hashmap
lib-tde.datastrucuture.hashmap.delete (key) Delete a key from the hashmap
lib-tde.datastrucuture.hashmap.get (key) Get a key from the hashmap


Static module functions

lib-tde.datastrucuture.hashmap () -> table
Create a new hashmap

Returns:

    table A table containing the hashmap methods

Usage:

    -- This will create a new empty hashmap
     lib-tde.datastrucuture.hashmap()
lib-tde.datastrucuture.hashmap.add (key, value)
Add a key value pair to the hashmap

Parameters:

  • key string The key used to identify the value
  • value object Any possible object that can be hold in the hashmap (string, number, table, etc)

Usage:

    -- Add the string hello to the key tde
     hashmap.add("tde", "hello")
lib-tde.datastrucuture.hashmap.delete (key)
Delete a key from the hashmap

Parameters:

  • key string The key used to identify the value

Usage:

    -- Remove the key tde from the hashmap in case it exists
     hashmap.delete("tde")
lib-tde.datastrucuture.hashmap.get (key)
Get a key from the hashmap

Parameters:

  • key string The key used to identify the value

Usage:

    -- Return the value of the key, if it doesn't exist return nil
     hashmap.get("tde") -- returns "hello"
generated by LDoc 1.4.6 Build with 💜 By F0xedb Last updated 2021-05-21 03:30:15