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

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.lrucache

LRU cache for Terra, size-limited and count-limited


--[[

	LRU cache for Terra, size-limited and count-limited.
	Written by Cosmin Apreutesei. Public Domain.

	* Pair pointers are not valid between put() calls, use indices!
	* Breaks if trying to put a key that's already in the cache.
	* Cache items are ref-counted, get() and put() both increase the refcount
	and forget() decreases it. Ref'ed items never get removed from the cache,
	instead the cache grows beyond max_size and/or max_count.

	local C = cache{key_t=,val_t=,...}        create type from Lua
	var c = cache(key_t,val_t,[size_t=int])   create value from Terra
	c:init()                                  initialize (for struct members)
	c:free()                                  free
	c:clear()                                 clear (but preserve memory)
	c.min_capacity = n                        (write/only) preallocate a number of items
	c:shrink(max_size, max_count)             shrink (but don't free memory)
	c.max_size                                (read/write) max bytesize
	c.max_count                               (read/write) max number of items
	c.size                                    (read/only) current size
	c.count                                   (read/only) current number of items

	c:get(k) -> i,&pair | -1,nil              get k/v pair by key
	c:put(k,v) -> i,&pair                     put k/v pair
	c:pair(i) -> &pair                        lookup pair
	c:forget(i)                               forget pair

]]

See the source code for more info.


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

Top