potion  0.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PNTuple Class Reference

a tuple is an array of PNs. More...

#include <potion.h>

Public Member Functions

#define PN_IS_EMPTY(T)   (PN_TUPLE_LEN(T) == 0)
 
#define PN_TUP0()   potion_tuple_empty(P)
 
#define PN_TUP(X)   potion_tuple_new(P, X)
 
#define PN_PUSH(T, X)   potion_tuple_push(P, T, (PN)X)
 
#define PN_SHIFT(T)   potion_tuple_shift(P, 0, T)
 
#define PN_GET(T, X)   potion_tuple_find(P, T, X)
 
#define PN_PUT(T, X)   potion_tuple_push_unless(P, T, X)
 
#define PN_GET_TUPLE(t)   ((struct PNTuple *)potion_fwd((PN)t))
 
#define PN_TUPLE_LEN(t)   PN_GET_TUPLE(t)->len
 
#define PN_TUPLE_AT(t, n)   PN_GET_TUPLE(t)->set[n]
 
#define PN_TUPLE_COUNT(T, I, B)
 
#define PN_TUPLE_EACH(T, I, V, B)
 
PN potion_tuple_append (Potion *P, PN cl, PN self, PN value)
 
PN potion_tuple_at (Potion *P, PN cl, PN self, PN index)
 
static PN potion_tuple_clone (Potion *P, PN cl, PN self)
 
static PN potion_tuple_slice (Potion *P, PN cl, PN self, PN start, PN end)
 
PN potion_tuple_each (Potion *P, PN cl, PN self, PN block)
 
PN potion_tuple_first (Potion *P, PN cl, PN self)
 
PN potion_tuple_join (Potion *P, PN cl, PN self, PN sep)
 
PN potion_tuple_last (Potion *P, PN cl, PN self)
 
PN potion_tuple_string (Potion *P, PN cl, PN self)
 
PN potion_tuple_pop (Potion *P, PN cl, PN self)
 
PN potion_tuple_put (Potion *P, PN cl, PN self, PN key, PN value)
 
PN potion_tuple_unshift (Potion *P, PN cl, PN self, PN value)
 
PN potion_tuple_shift (Potion *P, PN cl, PN self)
 
PN potion_tuple_print (Potion *P, PN cl, PN self)
 
PN potion_tuple_length (Potion *P, PN cl, PN self)
 
PN potion_tuple_reverse (Potion *P, PN cl, PN self)
 
PN potion_tuple_remove (Potion *P, PN cl, PN self, PN index)
 
PN potion_tuple_delete (Potion *P, PN cl, PN self, PN index)
 
PN potion_tuple_nreverse (Potion *P, PN cl, PN self)
 
PN potion_tuple_bsearch (Potion *P, PN cl, PN self, PN x)
 
static PN potion_tuple_sort (Potion *P, PN cl, PN self, PN cmp)
 TODO: bitonic __m128 sort (SSE accelerated) for typed tuples E.g. More...
 
PN potion_tuple_ins_sort (Potion *P, PN cl, PN self, PN cmp)
 

Data Fields

 PN_OBJECT_HEADER
 PNType vt; PNUniq uniq. More...
 
PN_SIZE len
 
PN_SIZE alloc
 overallocate a bit More...
 
PN set []
 

Detailed Description

a tuple is an array of PNs.

list (array)

volatile.

Definition at line 468 of file potion.h.

Member Function Documentation

PN potion_tuple_append ( Potion P,
PN  cl,
PN  self,
PN  value 
)

"append" and "push" method. (to the end)

Parameters
valuePN
Returns
PNTuple

Definition at line 271 of file table.c.

PN potion_tuple_at ( Potion P,
PN  cl,
PN  self,
PN  index 
)

"at" method, the safe generic tuple accessor. Use the tpl[index] syntax for the fast unchecked version.

t=(0,1,2)
t(0) #=> 0
t(1) #=> 1
t(-1) #=> 2
Parameters
indexPNInteger. If negative, count from end. If too large, return nil.
Returns
tuple element at index

Definition at line 309 of file table.c.

static PN potion_tuple_clone ( Potion P,
PN  cl,
PN  self 
)

"clone" method.

Returns
new PNTuple

Definition at line 321 of file table.c.

static PN potion_tuple_slice ( Potion P,
PN  cl,
PN  self,
PN  start,
PN  end 
)

Extract slice copy of a tuple, similar to strings. Supports negative indices and end<start.

(0,1,2) slice #=> (0,1,2)
(0,1,2) slice(1) #=> (1,2)
(0,1,2) slice(0,1) #=> (0,1)
(0,1,2) slice(-1) #=> (2)
(0,1,2) slice(1,1) #=> (1)
(0,1,2) slice(1,-1) #=> (0,1)
(0,1,2) slice(2,-1) #=> (2)
(0,1,2) slice(-1,-2) #=> (0,1)
Parameters
startPNInteger. Default 0. If negative, count from end. If too large, return nil.
endPNInteger. Optional, default last index. If negative, count from end. If too large, return nil.
Returns
new PNTuple

Definition at line 347 of file table.c.

PN potion_tuple_each ( Potion P,
PN  cl,
PN  self,
PN  block 
)

"each" method. call block on each member (linear order)

Parameters
blockPNClosure
Returns
self PNTuple

Definition at line 383 of file table.c.

PN potion_tuple_first ( Potion P,
PN  cl,
PN  self 
)

"first" method.

Returns
first PN or PN_NIL if the PNTuple is empty

Definition at line 398 of file table.c.

PN potion_tuple_join ( Potion P,
PN  cl,
PN  self,
PN  sep 
)

"join" method.

Parameters
sepPNString
Returns
PNBytes

Definition at line 408 of file table.c.

PN potion_tuple_last ( Potion P,
PN  cl,
PN  self 
)

"last" method.

Returns
last PN or PN_NIL if the PNTuple is empty

Definition at line 421 of file table.c.

PN potion_tuple_string ( Potion P,
PN  cl,
PN  self 
)

"string" method. serializable ascii dump

Returns
PNString

Definition at line 431 of file table.c.

PN potion_tuple_pop ( Potion P,
PN  cl,
PN  self 
)

"pop" method. remove the last element and return it

Returns
last PN

Definition at line 450 of file table.c.

PN potion_tuple_put ( Potion P,
PN  cl,
PN  self,
PN  key,
PN  value 
)

"put" method. write value at index key Note: If the key is not a number converts the tuple to a table

Parameters
keyPNInteger index
valuePN
Returns
self PNTuple

Definition at line 466 of file table.c.

PN potion_tuple_unshift ( Potion P,
PN  cl,
PN  self,
PN  value 
)

"unshift" method. put new element to the front

Parameters
valuePN
Returns
PNTuple

Definition at line 485 of file table.c.

PN potion_tuple_shift ( Potion P,
PN  cl,
PN  self 
)

"shift" method. remove first element and return it

Parameters
valuePN
Returns
PNTuple

Definition at line 503 of file table.c.

PN potion_tuple_print ( Potion P,
PN  cl,
PN  self 
)

"print" method. call print on all elements

Returns
PN_NIL

Definition at line 517 of file table.c.

PN potion_tuple_length ( Potion P,
PN  cl,
PN  self 
)

"length" of a list. Number of elements

Returns
PNInteger

Definition at line 528 of file table.c.

PN potion_tuple_reverse ( Potion P,
PN  cl,
PN  self 
)

"reverse" a list non-destructively

Returns
a new PNTuple

Definition at line 536 of file table.c.

PN potion_tuple_remove ( Potion P,
PN  cl,
PN  self,
PN  index 
)

"remove" an element at index from tuple.

See also
potion_tuple_delete for the destructive variant
Returns
a copy of PNTuple with one less element

Definition at line 559 of file table.c.

PN potion_tuple_delete ( Potion P,
PN  cl,
PN  self,
PN  index 
)

destructively "delete" an element at index from tuple.

See also
potion_tuple_remove for the copying variant
Returns
PNTuple

Definition at line 580 of file table.c.

PN potion_tuple_nreverse ( Potion P,
PN  cl,
PN  self 
)

"reverse" a list destructively

Returns
the same PNTuple with reversed elements

Definition at line 596 of file table.c.

PN potion_tuple_bsearch ( Potion P,
PN  cl,
PN  self,
PN  x 
)

search for value x in an ordered PNTuple, ordered by PN_UNIQ.

Parameters
xPN (PNUniq in fact)
Returns
found index or false

Definition at line 614 of file table.c.

static PN potion_tuple_sort ( Potion P,
PN  cl,
PN  self,
PN  cmp 
)

TODO: bitonic __m128 sort (SSE accelerated) for typed tuples E.g.

sort elements, safe non-destructive version. generic instable quicksort, via in-place quicksort partition algorithm.

Parameters
comparemethod cmp(a,b) => -1,0,1, or NIL for UNIQ (random, but stable), or true for ascending or false for descending order by value. true or false will fail on most complex data types, works only with num (ints).
Returns
a sorted copy of the tuple alike https://github.com/zerovm/zerovm-samples/blob/master/bitonic_sort/src/sort_uint_proper_with_args.c
Parameters
selfsort tuple
cmpcmp method for 2 values, returning -1,0,1

Definition at line 696 of file table.c.

PN potion_tuple_ins_sort ( Potion P,
PN  cl,
PN  self,
PN  cmp 
)

"ins_sort" method, used internally,

Warning
destructive. sort PNTuple by UNIQ, uses insertion_sort for less than 10 elements otherwise quicksort.
Parameters
cmp(optional) comparison closure: (a,b) a < b ? -1 : a == b ? 0 : 1. The default sort method is not by value, it is by uniq (random, but stable).
Returns
the same, but sorted PNTuple
See also
potion_tuple_sort for the safe variant and cmp variants.

Definition at line 716 of file table.c.

Field Documentation

PNTuple::PN_OBJECT_HEADER

PNType vt; PNUniq uniq.

Definition at line 469 of file potion.h.

PN_SIZE PNTuple::len

Definition at line 470 of file potion.h.

PN_SIZE PNTuple::alloc

overallocate a bit

Definition at line 471 of file potion.h.

PN PNTuple::set[]

Definition at line 472 of file potion.h.


The documentation for this class was generated from the following files: