potion  0.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
table.c File Reference

implement unordered hashes and ordered lists (PNTable and PNTuple) More...

#include <stdio.h>
#include <stdlib.h>
#include "potion.h"
#include "internal.h"
#include "khash.h"
#include "table.h"
+ Include dependency graph for table.c:

Go to the source code of this file.

Macros

#define NEW_TUPLE(t, size)
 
#define GET(i)   t->set[i]
 
#define SET(i, v)   t->set[i] = v
 
#define SWAP(a, b)
 

Functions

PN potion_table_cast (Potion *P, 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 More...
 
static PN potion_table_clone (Potion *P, PN cl, PN self)
 
PN potion_tuple_empty (Potion *P)
 
PN potion_tuple_with_size (Potion *P, unsigned long size)
 
PN potion_tuple_new (Potion *P, PN value)
 
PN potion_tuple_push (Potion *P, PN tuple, PN value)
 
PN_SIZE potion_tuple_find (Potion *P, PN tuple, PN value)
 Return index of found value or PN_NONE. More...
 
PN_SIZE potion_tuple_push_unless (Potion *P, PN tuple, PN value)
 
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 More...
 
static PN potion_tuple_cmp (Potion *P, PN cl, PN self, PN value)
 
void potion_table_init (Potion *P)
 

Detailed Description

implement unordered hashes and ordered lists (PNTable and PNTuple)

Definition in file table.c.

Macro Definition Documentation

#define NEW_TUPLE (   t,
  size 
)
Value:
vPN(Tuple) t = PN_ALLOC_N(PN_TTUPLE, struct PNTuple, size * sizeof(PN)); \
t->alloc = t->len = size
#define vPN(t)
Definition: potion.h:132
a tuple is an array of PNs.
Definition: potion.h:468
#define PN_ALLOC_N(V, T, C)
Definition: internal.h:13
#define PN_TTUPLE
Definition: potion.h:115
volatile _PN PN
Definition: potion.h:81

Definition at line 16 of file table.c.

#define GET (   i)    t->set[i]

Definition at line 547 of file table.c.

#define SET (   i,
 
)    t->set[i] = v

Definition at line 548 of file table.c.

#define SWAP (   a,
 
)
Value:
if (a != b) { \
t->set[a] ^= GET(b); \
t->set[b] ^= GET(a); \
t->set[a] ^= GET(b); }
#define GET(i)
Definition: table.c:547

Definition at line 550 of file table.c.

Function Documentation

PN potion_table_cast ( Potion P,
PN  self 
)
Returns
self PNTable

Definition at line 47 of file table.c.

PN potion_table_set ( Potion P,
PN  self,
PN  key,
PN  value 
)

helper function for potion_table_put:"put", accepts tuple or table

Parameters
keyPN
valuePN
Returns
self PNTable

Definition at line 126 of file table.c.

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

Definition at line 141 of file table.c.

PN potion_tuple_empty ( Potion P)

Definition at line 235 of file table.c.

PN potion_tuple_with_size ( Potion P,
unsigned long  size 
)

Definition at line 242 of file table.c.

PN potion_tuple_new ( Potion P,
PN  value 
)

Definition at line 247 of file table.c.

PN potion_tuple_push ( Potion P,
PN  tuple,
PN  value 
)

Definition at line 254 of file table.c.

PN_SIZE potion_tuple_find ( Potion P,
PN  tuple,
PN  value 
)

Return index of found value or PN_NONE.

Parameters
tuplePNTuple
valuePN
Returns
int

Definition at line 280 of file table.c.

PN_SIZE potion_tuple_push_unless ( Potion P,
PN  tuple,
PN  value 
)
Parameters
tuplePNTuple
valuePN

Definition at line 290 of file table.c.

static void potion_sort_internal ( Potion P,
PN  cl,
PN  self,
PN_SIZE  from,
PN_SIZE  to,
PN  cmp 
)
static

space-efficient but destructive and not-stable qsort

Parameters
selfsort data
fromfirst index, usually 0
tolast index, usually len-1
cmpcmp method for 2 values, returning -1,0,1

Definition at line 634 of file table.c.

static PN potion_tuple_cmp ( Potion P,
PN  cl,
PN  self,
PN  value 
)
static

Definition at line 774 of file table.c.

void potion_table_init ( Potion P)

Definition at line 821 of file table.c.