lights FAQ Forum github.com/luapower/terra.hashmap
This package
terra.hashmap

Terra Standard Libraries
terra.low
terra.arrayview
terra.dynarray
terra.hashmap
terra.phf
terra.linkedlist
terra.fixedfreelist
terra.arrayfreelist
terra.lrucache
terra.bitarray
terra.utf8
terra.random

terra.hashmap

Hashmap type for Terra


--[[

	Hashmap type for Terra.
	Written by Cosmin Apreutesei. Public Domain.

	Port of khash.h v0.2.8 from github.com/attractivechaos/klib (MIT License).

	local M = map(key_t,val_t,[size_t=int])     create a map type
	local M = map{key_t=,val_t=...}             create a map type
	var m   = map(key_t,val_t,[size_t=int])     create a map object
	var m   = M(nil)                            nil-cast (for use in global())

	local S = set(key_t,[size_t=int])           create a set type
	local S = set{key_t=,...}                   create a set type
	var s   = set(key_t,[size_t=int])           create a set object
	var s   = S(nil)                            nil-cast (for use in global())

	m|s:init() | fill(&m|&s)                    initialize (for struct members)
	m|s:free()                                  free the hashmap
	m|s:clear()                                 clear but keep the buffers

	m|s.count                                   (read/only) number of pairs
	m|s.capacity                                (read/write) grow/shrink hashmap
	m|s.min_capacity                            (write/only) grow hashmap

	m|s:index(k[,default]) -> i                 lookup key and return pair index
	m|s:setkey(k) -> m.PRESENT|ABSENT|DELETED|-1, i|-1  occupy a key
	m|s:remove_at_index(i) -> found?            remove/free pair at i
	m|s:has_at_index(i) -> found?               check if index is occupied
	m|s:key_at_index(i) -> k                    (unchecked!) get key at i
	m|s:noderef_key_at_index(i) -> k            (unchecked!) get no-deref key at i
	m:val_at_index(i) -> v                      (unchecked!) get value at i
	m|s:next_index([last_i]) -> i|-1            next occupied index

	m|s:has(k) -> found?                        check if key is in map
	m:at(k[,default]) -> &v                     get &value for key
	m[:get](k[,default]) -> v                   get value for key
	m:set(k,v) -> i                             add or get key and set value
	m:set(k) -> &v                              add or get key and get &value
	m:add(k,v) -> i|-1                          add key/val pair if key doesn't exist
	m:add(k) -> &v|nil                          add key if doesn't exist and get &value
	m:remove(k) -> found?                       remove/free pair
	s:set(k) -> i                               add or get key
	s:add(k) -> i|-1                            add key if doesn't exist

	for &k,&v in m do ... end                   iterate key/val pairs in a map
	for &k in s do ... end                      iterate keys in a set

	m|s:merge(m|s)                              add new pairs/keys from another map/set
	m|s:update(m|s)                             update pairs/keys, overriding values

]]

See the source code for more info.


Package:terra.hashmap
Pkg type:Terra
Version: c94bcbc
Last commit:
Author: Cosmin Apreutesei
License: Public Domain
Requires: +terra.low  +glue  +luajit  +pp 
Required by: terra.low 

Top