Module flower.table
The next group of functions extends the default lua table implementation to include some additional useful methods.
Info:
- Release: V3.0.0
- Author: Makoto
Functions
indexOf (array, value) | Returns the position found by searching for a matching value from an array. |
keyOf (src, val) | Same as indexOf, only for key values (slower) Author:Nenad Katic |
copy (src, dest) | Copy the table shallowly (i.e. |
deepCopy (src, dest) | Copy the table deeply (i.e. |
insertIfAbsent (t, o) | Adds an element to the table if and only if the value did not already exist. |
insertElement (t, o) | Adds an element to the table. |
removeElement (t, o) | Removes the element from the table. |
bininsert (t, value, fcomp) | Inserts a given value through BinaryInsert into the table sorted by [, comp]. |
Functions
- indexOf (array, value)
-
Returns the position found by searching for a matching value from an array.
Parameters:
- array table array
- value Search value
Returns:
-
the index number if the value is found, or 0 if not found.
- keyOf (src, val)
-
Same as indexOf, only for key values (slower)
Author:Nenad Katic
Parameters:
- src
- val
- copy (src, dest)
-
Copy the table shallowly (i.e. do not create recursive copies of values)
Parameters:
- src copy
- dest (option)Destination
Returns:
-
dest
- deepCopy (src, dest)
-
Copy the table deeply (i.e. create recursive copies of values)
Parameters:
- src copy
- dest (option)Destination
Returns:
-
dest
- insertIfAbsent (t, o)
-
Adds an element to the table if and only if the value did not already exist.
Parameters:
- t table
- o element
Returns:
-
If it already exists, returns false. If it did not previously exist, returns true.
- insertElement (t, o)
-
Adds an element to the table.
Parameters:
- t table
- o element
Returns:
-
true
- removeElement (t, o)
-
Removes the element from the table.
If the element existed, then returns its index value.
If the element did not previously exist, then return 0.
Parameters:
- t table
- o element
Returns:
-
index
- bininsert (t, value, fcomp)
-
Inserts a given value through BinaryInsert into the table sorted by [, comp].
If 'comp' is given, then it must be a function that receives
two table elements, and returns true when the first is less
than the second, e.g. comp = function(a, b) return a > b end,
will give a sorted table, with the biggest value on position 1.
[, comp] behaves as in table.sort(table, value [, comp])
returns the index where 'value' was inserted
Parameters:
- t table
- value value
- fcomp Compare function
Returns:
-
index where 'value' was inserted