// generated by insrcdata version 0.2.0 #include "insrcdata.h" #include #include #include const leave_t LEAVE_TABLE[LEAVE_TABLE_COUNT] = { {"Terrier", "A1", 2, }, {"Bulldog", "A1", 2, }, {"Husky", "A1", 2, }, {"Abyssinian ", "A2", 3, }, {"Persian", "A2", 3, }, {"Siamese", "A2", 3, }, {"Begonia", "B1", 5, }, {"Clematis", "B1", 5, }, {"Oak", "B2", 6, }, }; const leave_t* leave_next(leave_iter_t* idx) { return idx->ptrend ? &LEAVE_TABLE[*idx->ptr++] : NULL; } static unsigned const LEAVE_CHAPTER_INDEX_COUNT = 9; static uint8_t LEAVE_CHAPTER_INDEX [LEAVE_CHAPTER_INDEX_COUNT] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, }; const chapter_t CHAPTER_TABLE[CHAPTER_TABLE_COUNT] = { {"root", "0", 0, }, {"animals", "A", 0, }, {"dogs", "A1", 1, }, {"cats", "A2", 1, }, {"plants", "B", 0, }, {"flowers", "B1", 4, }, {"trees", "B2", 4, }, }; const chapter_t* chapter_next(chapter_iter_t* idx) { return idx->ptrend ? &CHAPTER_TABLE[*idx->ptr++] : NULL; } static unsigned const CHAPTER_CODE_INDEX_COUNT = 7; static uint8_t CHAPTER_CODE_INDEX [CHAPTER_CODE_INDEX_COUNT] = { 0, 1, 2, 3, 4, 5, 6, }; static unsigned const CHAPTER_PARENT_INDEX_COUNT = 7; static uint8_t CHAPTER_PARENT_INDEX [CHAPTER_PARENT_INDEX_COUNT] = { 0, 1, 4, 2, 3, 5, 6, }; const chapter_t* leave_chapter(const leave_t* s) { return &CHAPTER_TABLE[s->chapter_];} chapter_iter_t chapter_code_range( const char* start, const char* stop) { uint8_t* lo = CHAPTER_CODE_INDEX; uint8_t* hi = CHAPTER_CODE_INDEX + CHAPTER_CODE_INDEX_COUNT; while( lo < hi ){ uint8_t* mid = lo + ( hi-lo)/2; if( strcmp(start,CHAPTER_TABLE[*mid].code_ )>0 ){ lo = mid + 1; } else { hi = mid; } } uint8_t* begin = lo; hi = CHAPTER_CODE_INDEX + CHAPTER_CODE_INDEX_COUNT; while( lo < hi ){ uint8_t* mid = lo + ( hi-lo)/2; if( strcmp(stop,CHAPTER_TABLE[*mid].code_ )<0 ){ hi = mid; } else { lo = mid + 1; } } chapter_iter_t res = { begin, lo }; return res; } const chapter_t* chapter_parent(const chapter_t* s) { return &CHAPTER_TABLE[s->parent_];} leave_iter_t chapter_leaves(const chapter_t* s) { long cons = s - CHAPTER_TABLE; // bissect left uint8_t* lo = LEAVE_CHAPTER_INDEX; uint8_t* hi = LEAVE_CHAPTER_INDEX + LEAVE_CHAPTER_INDEX_COUNT; while( lo < hi ){ uint8_t* mid = lo + ( hi-lo)/2; if ( cons > LEAVE_TABLE[*mid].chapter_ ) { lo = mid + 1; } else { hi = mid; } } uint8_t* begin = lo; // bissect-right hi = LEAVE_CHAPTER_INDEX + LEAVE_CHAPTER_INDEX_COUNT; while( lo < hi ){ uint8_t* mid = lo + ( hi-lo)/2; if( cons < LEAVE_TABLE[*mid].chapter_ ) { hi = mid; } else { lo = mid + 1; } } leave_iter_t res = { begin, lo }; return res; }