Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (53 sloc) 2.02 KB
This component implements Ten's Record data type, which is a form of
hashmap frontent that uses a shared lookup table (Index) internally.
This relationship between records and indices is especially important
to Ten, both this implementation and as a language, and is explored in
#ifndef ten_rec_h
#define ten_rec_h
#include "ten_types.h"
#include "ten_tables.h"
struct Record {
// A pointer to the Record's associated index. This
// is paired with a 'sep' tag, indicating if the Record
// has been 'separated' from the Index; so can't add
// new fields. We do this separation lazily to avoid
// the copy overhead if possible, so the first `def`
// after the Record has been separated will result in
// its Index being replaced with a copy of the original.
TPtr idx;
// A pointer to the array of field values, tagged with
// the array's size given as a row number of the
// recCapTable table.
TPtr vals;
#define recSize( STATE, REC ) (sizeof(Record))
#define recTrav( STATE, REC ) (recTraverse( STATE, REC ))
#define recDest( STATE, REC ) (recDestruct( STATE, REC ))
#define recCap( REC ) (recCapTable[tpGetTag( (REC)->vals )])
#define recVals( REC ) (tpGetPtr( (REC)->vals ))
#define recIdx( REC ) (tpGetPtr( (REC)->idx ))
recInit( State* state );
recNew( State* state, Index* idx );
recSep( State* state, Record* rec );
recIndex( State* state, Record* rec );
recDef( State* state, Record* rec, TVal key, TVal val );
recSet( State* state, Record* rec, TVal key, TVal val );
recGet( State* state, Record* rec, TVal key );
typedef void (*RecEntryCb)( State* state, void* udat, TVal key, TVal val );
recForEach( State* state, Record* rec, void* udat, RecEntryCb cb );
recTraverse( State* state, Record* rec );
recDestruct( State* state, Record* rec );
You can’t perform that action at this time.