static bool parse_next_key(struct block_iter *bi) { bi->current = next_entry_offset(bi); uint8_t *p = bi->data + bi->current; uint8_t *limit = bi->data + bi->restarts; if (p >= limit) { /* no more entries to return, mark as invalid */ bi->current = bi->restarts; bi->restart_index = bi->num_restarts; return (false); } /* decode next entry */ uint32_t shared, non_shared, value_length; p = decode_entry(p, limit, &shared, &non_shared, &value_length); assert(!(p == NULL || ubuf_size(bi->key) < shared)); ubuf_clip(bi->key, shared); ubuf_append(bi->key, p, non_shared); bi->next = p + non_shared + value_length; bi->val = p + non_shared; bi->val_len = value_length; while (bi->restart_index + 1 < bi->num_restarts && get_restart_point(bi, bi->restart_index + 1) < bi->current) { bi->restart_index += 1; } return (true); }
bool Gpackage::extract_all(const WCHAR *path) { for (auto &e : entries_) { decode_entry(e, path); } return true; }
void QualityScoreEncoder::qualityscore_decompress(std::vector<read_t>& reads, char *filename) { b->read_pad_back(); uint32_t match_magic = 0; while (MAGIC_NUMBER != match_magic) { match_magic = b->read(32); } uint32_t entries = b->read(32); entry_len = b->read(32); reset(); if (reads.size() < entries) { std::cout << "\n[WARN] Current batch contains too many quality scores!\n - Expected entries: " << reads.size() << "\n - Quality scores: " << entries << std::endl; entries = reads.size(); } // Read in frequencies for (uint32_t i = 0; i < SYMBOL_SIZE; i++) { frequency[i] = b->read(32); } // Read in subbatch sizes uint32_t num_subbatch = b->read(32); uint32_t subbatch_entries[num_subbatch+1]; subbatch_entries[0] = 0; for (uint32_t i = 0; i < num_subbatch; i++) subbatch_entries[i+1] = b->read(32); for (uint32_t i = 0; i < num_subbatch; i++) { b->read_pad_back(); uint32_t match_magic = 0; while (MAGIC_NUMBER != match_magic) { match_magic = b->read(32); } value = b->read(VALUE_BITS); pending_bits = 0; high = MAX_VALUE; low = 0; for (uint32_t j = subbatch_entries[i]; j < subbatch_entries[i+1]; j++) { decode_entry(reads[j]); } } }
void block_iter_seek(struct block_iter *bi, const uint8_t *target, size_t target_len) { /* binary search in restart array to find the first restart point * with a key >= target */ uint32_t left = 0; uint32_t right = bi->num_restarts - 1; while (left < right) { uint32_t mid = (left + right + 1) / 2; uint32_t region_offset = get_restart_point(bi, mid); uint32_t shared, non_shared, value_length; const uint8_t *key_ptr = decode_entry(bi->data + region_offset, bi->data + bi->restarts, &shared, &non_shared, &value_length); if (key_ptr == NULL || (shared != 0)) { /* corruption */ return; } if (bytes_compare(key_ptr, non_shared, target, target_len) < 0) { /* key at "mid" is smaller than "target", therefore all * keys before "mid" are uninteresting */ left = mid; } else { /* key at "mid" is larger than "target", therefore all * keys at or before "mid" are uninteresting */ right = mid - 1; } } /* linear search within restart block for first key >= target */ seek_to_restart_point(bi, left); for (;;) { if (!parse_next_key(bi)) return; if (bytes_compare(ubuf_data(bi->key), ubuf_size(bi->key), target, target_len) >= 0) { return; } } }
CTIesrDict::Errors CTIesrDict::GetPron( const char *aWord, char aPron[], char *aPronString ) { CTIesrDict::Errors error; int idx; char *ucWord; // Delete any existing lookup for GetPronEntry and GetNextEntry delete [] m_word; m_word = NULL; delete [] m_defaultPron; m_defaultPron = NULL; m_entryLocation = 0; m_entryNumber = 0; // Modifiable buffer holding word to look up in upper case try { ucWord = new char[ strlen( aWord ) + 1 ]; } catch( std::bad_alloc &ex ) { return ErrMemory; } strcpy( ucWord, aWord ); chrtoupper( ucWord ); // Get the default pronunciation error = GetDefaultPron( ucWord, aPron ); if( error != ErrNone ) { delete [] ucWord; return ErrFail; } #ifdef _TIESRDICT_USE_TIESRDT // Convert word to indices if using TIesrDT and letter value >127 if( doLetterMap ) { error = map_dt_letters( ucWord ); if( error != ErrNone ) { delete [] ucWord; return error; } } #endif /* dictionary lookup */ idx = lookup( ucWord ); // If word found in dictionary, do use the exception if( idx != -1 ) { /* use exception.*/ // Note: decode_entry finds and uses first word entry in dictionary decode_entry( ucWord, idx, aPron ); } // Done with word text delete [] ucWord; // output the pronunciation string from dictionary lookup if( aPronString != NULL ) { PronToString( aPron, aPronString ); } return ErrNone; }