Skip to content
Permalink
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
`../docs/articles/Records.md`.
***********************************************************************/
#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 ))
void
recInit( State* state );
Record*
recNew( State* state, Index* idx );
void
recSep( State* state, Record* rec );
Index*
recIndex( State* state, Record* rec );
void
recDef( State* state, Record* rec, TVal key, TVal val );
void
recSet( State* state, Record* rec, TVal key, TVal val );
TVal
recGet( State* state, Record* rec, TVal key );
typedef void (*RecEntryCb)( State* state, void* udat, TVal key, TVal val );
void
recForEach( State* state, Record* rec, void* udat, RecEntryCb cb );
void
recTraverse( State* state, Record* rec );
void
recDestruct( State* state, Record* rec );
#endif
You can’t perform that action at this time.