lights FAQ Forum github.com/luapower/terra.arrayview
This package
terra.arrayview
terra.rawstringview

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

Array view type for Terra


--[[

	Array view type for Terra.
	Written by Cosmin Apreutesei. Public domain.

	An array view maps the idea of a finite array onto a memory location.

	local V = arrayview{T=,[size_t=int],[cmp=]} create a type from Lua
	local V = arrayview(T, [size_t=int],[cmp])  create a type from Lua
	var v =   arrayview{T=,[size_t=int],[cmp=]} create a value from Terra
	var v =   arrayview(T, [size_t=int],[cmp])  create a value from Terra
	var v =   arrayview(T, elements,len[ ,...]) create a value from Terra
	var v = V(nil)                              nil-cast (for use in global())
	var v = V{elements,len}                     field order is part of the API
	var v = V{elements=,len=}                   fields are part of the API

	v.elements, v.len                           fields are part of the API

	v:clamp(i) -> i                             clamp i to valid index
	v:index(i[,default]) -> i|default           valid positive index
	v(i[,default]) -> t|default                 get element at index
	v:at(i[,default]) -> &t|default             get element address at index
	v:set(i,t)                                  set element at index
	for i,&t in v do ... end                    iterate elements
	for i,&t in v:ipairs([forward],[step]) do.. iterate elements with iterator
	for i,&t in v:backwards([step]) do..        iterate elements backwards

	v:range(i,j) -> start,len                   v:range(5, 5) -> 5, 0
	v:sub(i,j) -> v                             create a sub-view
	v:copy(&t) -> &t                            copy to buffer
	v:copy(v) -> v                              copy to view
	v:fill(t)                                   set all elements to value

	v1 == v2                                    equality test
	v:__cmp(&v) -> -1,0,1                       comparison function
	v:__hash32(seed) -> h                       32bit hash function
	v:__hash64(seed) -> h                       64bit hash function

	v1 <|<=|==|>=|>|~= v2                       compare views

	cmp = {&T, &T} -> int32                     type of element comparison function
	v:sort([cmp])                               sort elements
	v:sort_desc()                               sort descending
	v:find(t[,default]) -> i                    find element
	v:count(t) -> n                             element occurences
	v:binsearch(t, [cmp]) -> i                  binsearch (sort the view first!)
	v:binsearch(t, v.lt|v.lte|v.gt|v.gte) -> i  binsearch with built-in cmp

	v:reverse()                                 reverse order of elements
	v:call(method, args...)                     call method on each element

	v:index(&t[,default]) -> i|default          element index by address
	v:next(&t,[&default]) -> &t|&default        next element
	v:prev(&t,[&default]) -> &t|&default        previous element

]]

See the source code for more info.


Package:terra.arrayview
Pkg type:Terra
Version: 74e393d
Last commit:
Author: Cosmin Apreutesei
License: Public Domain
Requires: +terra.dynarray  +terra.low  +glue  +luajit  +pp 
Required by: terra.dynarray  terra.utf8 

Top