16 #define NEW_TUPLE(t, size) \
17 vPN(Tuple) t = PN_ALLOC_N(PN_TTUPLE, struct PNTuple, size * sizeof(PN)); \
18 t->alloc = t->len = size
58 ((
struct PNFwd *)
self)->ptr = (
PN)t;
102 unsigned k =
kh_put(
PN, t, key, &ret);
146 t2 = kh_resize_PN(P, t2,
kh_size(t));
184 unsigned k2 =
kh_put(
PN, t2, v, &ret);
204 int i = 0;
unsigned k;
223 int i = 0;
unsigned k;
257 if (t->len >= t->alloc) {
261 t->set[t->len] = value;
283 if (v == value)
return i;
293 if (idx !=
PN_NONE)
return idx;
313 if (i >= len)
return PN_NIL;
356 if (i < 0) i = t1->len + i;
363 if (e < 0) e = t1->len + e;
365 if (l < 0) { i = e; l = labs(l) + 1; }
367 if (l > t1->len) l = t1->len;
369 DBG_vt(
"; splice(i=%ld,len=%ld)\n", i, l);
370 if (!l || i >= t1->len)
return PN_NIL;
424 if (len < 1)
return PN_NIL;
453 PN obj = t->set[t->len - 1];
488 if (t->len >= t->alloc) {
547 #define GET(i) t->set[i]
548 #define SET(i,v) t->set[i] = v
550 #define SWAP(a,b) if (a != b) { \
551 t->set[a] ^= GET(b); \
552 t->set[b] ^= GET(a); \
553 t->set[a] ^= GET(b); }
602 for (i = 0; i < (
PN_SIZE)(len/2); i++) {
618 long i = 0, j = t->
len - 1;
620 long m = j + ((i - j) / 2);
646 PN_SIZE i, index = from + (to - from)/2;
647 PN pivot =
GET(index);
654 for (i=from; i < to-1; i++) {
658 for (i=from; i < to; i++) {
659 if (
GET(i) <= pivot) {
660 SWAP(i, index); index++;
664 for (i=from; i < to; i++) {
665 if (
GET(i) > pivot) {
SWAP(i, index); index++;
670 for (i=from; i < to; i++) {
671 if (
PN_INT(c->method(P, cl, cmp,
GET(i), pivot)) > 0)
672 {
SWAP(i, index); index++; }
724 for (i = 1; i < t->
len; i++) {
734 for (i = 1; i < t->
len; i++) {
736 while (j > 0 &&
PN_INT(c->method(P, cl, cmp,
GET(j-1),
GET(j))) > 0) {
743 for (i = 1; i < t->
len; i++) {
745 while (j > 0 &&
GET(j-1) >
GET(j)) {
752 for (i = 1; i < t->
len; i++) {
754 while (j > 0 &&
GET(j-1) <
GET(j)) {
#define PN_TUPLE_AT(t, n)
PN potion_tuple_ins_sort(Potion *P, PN cl, PN self, PN cmp)
forwarding pointer (in case of reallocation)
PN potion_table_remove(Potion *P, PN cl, PN self, PN key)
#define DBG_CHECK_TYPE(obj, type)
klib hash table library based on double hashing http://en.wikipedia.org/wiki/Double_hashing ...
#define NEW_TUPLE(t, size)
a tuple is an array of PNs.
#define PN_ALLOC_N(V, T, C)
#define PN_REALLOC(X, V, T, N)
PN_SIZE void potion_bytes_obj_string(Potion *, PN, PN)
PN potion_table_put(Potion *P, PN cl, PN self, PN key, PN value)
PN PN potion_byte_str(Potion *, const char *)
#define PN_MEMMOVE_N(DST, SRC, T, N)
PN potion_tuple_at(Potion *P, PN cl, PN self, PN index)
#define potion_method(RCV, MSG, FN, SIG)
PN_SIZE potion_tuple_push_unless(Potion *P, PN tuple, PN value)
static PN potion_table_values(Potion *P, PN cl, PN self)
PN potion_tuple_append(Potion *P, PN cl, PN self, PN value)
static PN potion_fwd(PN)
the potion type is the 't' in the vtable tuple (m,t)
static PN potion_tuple_slice(Potion *P, PN cl, PN self, PN start, PN end)
void potion_type_call_is(PN vt, PN cl)
sets the default call method of the PNVtable
#define kh_put(name, h, k, r)
void potion_table_init(Potion *P)
static void potion_sort_internal(Potion *P, PN cl, PN self, PN_SIZE from, PN_SIZE to, PN cmp)
space-efficient but destructive and not-stable qsort
standard objects act like C structs the fields are defined by the type and it's a fixed size...
static PN potion_table_keys(Potion *P, PN cl, PN self)
static PN potion_table_slice(Potion *P, PN cl, PN self, PN keys)
PN potion_tuple_join(Potion *P, PN cl, PN self, PN sep)
PN potion_tuple_shift(Potion *P, PN cl, PN self)
PN potion_table_empty(Potion *P)
PN potion_tuple_last(Potion *P, PN cl, PN self)
void potion_type_callset_is(PN vt, PN cl)
set default writer
PN potion_table_cast(Potion *P, PN self)
PN potion_tuple_unshift(Potion *P, PN cl, PN self, PN value)
static PN potion_tuple_cmp(Potion *P, PN cl, PN self, PN value)
PN potion_tuple_print(Potion *P, PN cl, PN self)
the table class, based on khash
PN potion_tuple_each(Potion *P, PN cl, PN self, PN block)
#define DBG_CHECK_TUPLE(obj)
static PN potion_tuple_clone(Potion *P, PN cl, PN self)
PN potion_tuple_put(Potion *P, PN cl, PN self, PN key, PN value)
#define PN_MEMCPY_N(X, Y, T, N)
PN potion_tuple_bsearch(Potion *P, PN cl, PN self, PN x)
PN potion_tuple_string(Potion *P, PN cl, PN self)
#define DBG_CHECK_INT(obj)
PN potion_tuple_with_size(Potion *P, unsigned long size)
PN potion_table_at(Potion *P, PN cl, PN self, PN key)
#define kh_del(name, h, k)
PN potion_lobby_list(Potion *P, PN cl, PN self, PN size)
PN potion_tuple_reverse(Potion *P, PN cl, PN self)
PN potion_tuple_remove(Potion *P, PN cl, PN self, PN index)
PN_SIZE potion_type_size(Potion *P, const struct PNObject *ptr)
PN potion_table_string(Potion *P, PN cl, PN self)
PN potion_tuple_empty(Potion *P)
#define kh_val(name, h, x)
PN potion_tuple_length(Potion *P, PN cl, PN self)
PN potion_tuple_new(Potion *P, PN value)
the global interpreter state P. currently singleton (not threads yet)
static PN potion_tuple_sort(Potion *P, PN cl, PN self, PN cmp)
TODO: bitonic __m128 sort (SSE accelerated) for typed tuples E.g.
PN_SIZE pn_printf(Potion *, PN, const char *,...) __attribute__((format(printf
#define kh_key(name, h, x)
PN potion_table_each(Potion *P, PN cl, PN self, PN block)
static PNType potion_type(PN obj)
either immediate (NUM,BOOL,NIL) or a fwd
#define PN_QUICK_FWD(t, obj)
PN_QUICK_FWD - doing a single fwd check after a possible realloc.
the central table type, based on core/khash.h
static PN potion_table_clone(Potion *P, PN cl, PN self)
PN potion_table_length(Potion *P, PN cl, PN self)
#define potion_send(RCV, MSG, ARGS...)
method caches (more great stuff from ian piumarta)
int potion_sig_arity(Potion *P, PN sig)
number of args of sig tuple, implements the potion_closure_arity method.
PN_SIZE potion_tuple_find(Potion *P, PN tuple, PN value)
Return index of found value or PN_NONE.
PN potion_tuple_delete(Potion *P, PN cl, PN self, PN index)
PN potion_tuple_push(Potion *P, PN tuple, PN value)
PN potion_tuple_pop(Potion *P, PN cl, PN self)
PN potion_table_set(Potion *P, PN self, PN key, PN value)
helper function for potion_table_put:"put", accepts tuple or table
PN potion_tuple_first(Potion *P, PN cl, PN self)
#define kh_exist(name, h, x)
PN potion_tuple_nreverse(Potion *P, PN cl, PN self)
#define PN_TUPLE_EACH(T, I, V, B)
void potion_fatal(char *message)
#define kh_get(name, h, k)