Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
libfsst::SymbolTable Struct Reference
Collaboration diagram for libfsst::SymbolTable:

Public Member Functions

void clear ()
bool hashInsert (Symbol s)
bool add (Symbol s)
u16 findLongestSymbol (Symbol s) const
 Find longest expansion, return code (= position in symbol table).
u16 findLongestSymbol (const u8 *cur, const u8 *end) const
void finalize (u8 zeroTerminated)

Public Attributes

u16 shortCodes [65536]
u16 byteCodes [256]
Symbol symbols [FSST_CODE_MAX]
Symbol hashTab [hashTabSize]
u16 nSymbols
u16 suffixLim
u16 terminator
bool zeroTerminated
u16 lenHisto [FSST_CODE_BITS]

Static Public Attributes

static const u32 hashTabSize = 1<<FSST_HASH_LOG2SIZE

Constructor & Destructor Documentation

◆ SymbolTable()

libfsst::SymbolTable::SymbolTable ( )
inline
450507 : nSymbols(0), suffixLim(FSST_CODE_MAX), terminator(0), zeroTerminated(false) {
450508 // stuff done once at startup
450509 for (u32 i=0; i<256; i++) {
450510 symbols[i] = Symbol(i,i|(1<<FSST_LEN_BITS)); // pseudo symbols
450511 }
450512 Symbol unused = Symbol((u8) 0,FSST_CODE_MASK); // single-char symbol, exception code
450513 for (u32 i=256; i<FSST_CODE_MAX; i++) {
450514 symbols[i] = unused; // we start with all symbols unused
450515 }
450516 // empty hash table
450517 Symbol s;
450518 s.val.num = 0;
450519 s.icl = FSST_ICL_FREE; //marks empty in hashtab
450520 for(u32 i=0; i<hashTabSize; i++)
450521 hashTab[i] = s;
450522
450523 // fill byteCodes[] with the pseudo code all bytes (escaped bytes)
450524 for(u32 i=0; i<256; i++)
450525 byteCodes[i] = (1<<FSST_LEN_BITS) | i;
450526
450527 // fill shortCodes[] with the pseudo code for the first byte of each two-byte pattern
450528 for(u32 i=0; i<65536; i++)
450529 shortCodes[i] = (1<<FSST_LEN_BITS) | (i&255);
450530
450531 memset(lenHisto, 0, sizeof(lenHisto)); // all unused
450532 }

Member Function Documentation

◆ clear()

void libfsst::SymbolTable::clear ( )
inline
450534 {
450535 // clear a symbolTable with minimal effort (only erase the used positions in it)
450536 memset(lenHisto, 0, sizeof(lenHisto)); // all unused
450537 for(u32 i=FSST_CODE_BASE; i<FSST_CODE_BASE+nSymbols; i++) {
450538 if (symbols[i].length() == 1) {
450539 u16 val = symbols[i].first();
450540 byteCodes[val] = (1<<FSST_LEN_BITS) | val;
450541 } else if (symbols[i].length() == 2) {
450542 u16 val = symbols[i].first2();
450543 shortCodes[val] = (1<<FSST_LEN_BITS) | (val&255);
450544 } else {
450545 u32 idx = symbols[i].hash() & (hashTabSize-1);
450546 hashTab[idx].val.num = 0;
450547 hashTab[idx].icl = FSST_ICL_FREE; //marks empty in hashtab
450548 }
450549 }
450550 nSymbols = 0; // no need to clean symbols[] as no symbols are used
450551 }

◆ hashInsert()

bool libfsst::SymbolTable::hashInsert ( Symbol s)
inline
450552 {
450553 u32 idx = s.hash() & (hashTabSize-1);
450554 bool taken = (hashTab[idx].icl < FSST_ICL_FREE);
450555 if (taken) return false; // collision in hash table
450556 hashTab[idx].icl = s.icl;
450557 hashTab[idx].store_num(s.load_num() & (0xFFFFFFFFFFFFFFFF >> (u8) s.icl));
450558 return true;
450559 }

◆ add()

bool libfsst::SymbolTable::add ( Symbol s)
inline
450560 {
450561 assert(FSST_CODE_BASE + nSymbols < FSST_CODE_MAX);
450562 u32 len = s.length();
450563 s.set_code_len(FSST_CODE_BASE + nSymbols, len);
450564 if (len == 1) {
450565 byteCodes[s.first()] = FSST_CODE_BASE + nSymbols + (1<<FSST_LEN_BITS); // len=1 (<<FSST_LEN_BITS)
450566 } else if (len == 2) {
450567 shortCodes[s.first2()] = FSST_CODE_BASE + nSymbols + (2<<FSST_LEN_BITS); // len=2 (<<FSST_LEN_BITS)
450568 } else if (!hashInsert(s)) {
450569 return false;
450570 }
450571 symbols[FSST_CODE_BASE + nSymbols++] = s;
450572 lenHisto[len-1]++;
450573 return true;
450574 }
#define assert(x)
Definition duckdb.cpp:486071

◆ findLongestSymbol() [1/2]

u16 libfsst::SymbolTable::findLongestSymbol ( Symbol s) const
inline

Find longest expansion, return code (= position in symbol table).

450576 {
450577 size_t idx = s.hash() & (hashTabSize-1);
450578 if (hashTab[idx].icl <= s.icl && hashTab[idx].load_num() == (s.load_num() & (0xFFFFFFFFFFFFFFFF >> ((u8) hashTab[idx].icl)))) {
450579 return (hashTab[idx].icl>>16) & FSST_CODE_MASK; // matched a long symbol
450580 }
450581 if (s.length() >= 2) {
450582 u16 code = shortCodes[s.first2()] & FSST_CODE_MASK;
450583 if (code >= FSST_CODE_BASE) return code;
450584 }
450585 return byteCodes[s.first()] & FSST_CODE_MASK;
450586 }

◆ findLongestSymbol() [2/2]

u16 libfsst::SymbolTable::findLongestSymbol ( const u8 * cur,
const u8 * end ) const
inline
450587 {
450588 return findLongestSymbol(Symbol(cur,end)); // represent the string as a temporary symbol
450589 }
u16 findLongestSymbol(Symbol s) const
Find longest expansion, return code (= position in symbol table).
Definition duckdb.cpp:450576

◆ finalize()

void libfsst::SymbolTable::finalize ( u8 zeroTerminated)
inline
450617 {
450618 assert(nSymbols <= 255);
450619 u8 newCode[256], rsum[8], byteLim = nSymbols - (lenHisto[0] - zeroTerminated);
450620
450621 // compute running sum of code lengths (starting offsets for each length)
450622 rsum[0] = byteLim; // 1-byte codes are highest
450623 rsum[1] = zeroTerminated;
450624 for(u32 i=1; i<7; i++)
450625 rsum[i+1] = rsum[i] + lenHisto[i];
450626
450627 // determine the new code for each symbol, ordered by length (and splitting 2byte symbols into two classes around suffixLim)
450628 suffixLim = rsum[1];
450629 symbols[newCode[0] = 0] = symbols[256]; // keep symbol 0 in place (for zeroTerminated cases only)
450630
450631 for(u32 i=zeroTerminated, j=rsum[2]; i<nSymbols; i++) {
450632 Symbol s1 = symbols[FSST_CODE_BASE+i];
450633 u32 len = s1.length(), opt = (len == 2)*nSymbols;
450634 if (opt) {
450635 u16 first2 = s1.first2();
450636 for(u32 k=0; k<opt; k++) {
450637 Symbol s2 = symbols[FSST_CODE_BASE+k];
450638 if (k != i && s2.length() > 1 && first2 == s2.first2()) // test if symbol k is a suffix of s
450639 opt = 0;
450640 }
450641 newCode[i] = opt?suffixLim++:--j; // symbols without a larger suffix have a code < suffixLim
450642 } else
450643 newCode[i] = rsum[len-1]++;
450644 s1.set_code_len(newCode[i],len);
450645 symbols[newCode[i]] = s1;
450646 }
450647 // renumber the codes in byteCodes[]
450648 for(u32 i=0; i<256; i++)
450649 if ((byteCodes[i] & FSST_CODE_MASK) >= FSST_CODE_BASE)
450650 byteCodes[i] = newCode[(u8) byteCodes[i]] + (1 << FSST_LEN_BITS);
450651 else
450652 byteCodes[i] = 511 + (1 << FSST_LEN_BITS);
450653
450654 // renumber the codes in shortCodes[]
450655 for(u32 i=0; i<65536; i++)
450656 if ((shortCodes[i] & FSST_CODE_MASK) >= FSST_CODE_BASE)
450657 shortCodes[i] = newCode[(u8) shortCodes[i]] + (shortCodes[i] & (15 << FSST_LEN_BITS));
450658 else
450659 shortCodes[i] = byteCodes[i&0xFF];
450660
450661 // replace the symbols in the hash table
450662 for(u32 i=0; i<hashTabSize; i++)
450663 if (hashTab[i].icl < FSST_ICL_FREE)
450664 hashTab[i] = symbols[newCode[(u8) hashTab[i].code()]];
450665 }

The documentation for this struct was generated from the following file: