-
Notifications
You must be signed in to change notification settings - Fork 0
/
nameTable.h
43 lines (34 loc) · 1.51 KB
/
nameTable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Jonathan(Jon) DuBois 2015. This file is part of LNZ. //
////////////////////////////////////////////////////////////////////////////////
#ifndef LNZ_NAMETABLE_H
#define LNZ_NAMETABLE_H
// A trie based name table associating strings with 64 bit integers. 0 is not a valid index; they begin at 1.
// This is fast but massive. It could be improved with embedded strings.
// If the same name is added more than once, the latest index added is returned when queried.
typedef struct indexNode{
u64 index;
struct indexNode* next;
} nameTableIndexNode;
typedef struct node{
struct node* continuations[ 256 ];
nameTableIndexNode* indices;
} nameTableNode;
typedef struct{
u64 size;
u64 bufsize;
nameTableNode* dict;
u8** revdict;
u64* revdictSizes;
} nameTable;
nameTable* newNameTable( void );
void deleteNameTable( nameTable* nt );
void addNameToTable( nameTable* nt, const u8* name, u64 namelen );
// Returns the 1-based index of a string, or 0 if there isn't one.
u64 getIndex( const nameTable* nt, const u8* name, u64 namelen );
// Returns the string associated with an index, indices are 1 based and there is no error checking. len is set to the length of the name.
const u8* getName( const nameTable* nt, u64 index, u64* len );
// Pops the last name added off.
void popNameTable( nameTable* nt );
void printNameTable( const nameTable* nt );
#endif //LNZ_NAMETABLE_H