22 #ifndef KALDI_UTIL_HASH_LIST_INL_H_    23 #define KALDI_UTIL_HASH_LIST_INL_H_    32   bucket_list_tail_ = 
static_cast<size_t>(-1);  
    40       bucket_list_tail_ == static_cast<size_t>(-1));  
    41   if (size > buckets_.size())
    42     buckets_.resize(size, HashBucket(0, NULL));
    45 template<
class I, 
class T>
    49   for (
size_t cur_bucket = bucket_list_tail_;
    50       cur_bucket != 
static_cast<size_t>(-1);
    51       cur_bucket = buckets_[cur_bucket].prev_bucket) {
    52     buckets_[cur_bucket].last_elem = NULL;  
    54   bucket_list_tail_ = 
static_cast<size_t>(-1);
    55   Elem *ans = list_head_;
    60 template<
class I, 
class T>
    65 template<
class I, 
class T>
    67   e->tail = freed_head_;
    71 template<
class I, 
class T>
    73   size_t index = (
static_cast<size_t>(key) % hash_size_);
    74   HashBucket &bucket = buckets_[index];
    75   if (bucket.last_elem == NULL) {
    78     Elem *head = (bucket.prev_bucket == 
static_cast<size_t>(-1) ?
    80                   buckets_[bucket.prev_bucket].last_elem->tail),
    81         *tail = bucket.last_elem->
tail;
    82     for (Elem *e = head; e != tail; e = e->tail)
    83       if (e->key == key) 
return e;
    88 template<
class I, 
class T>
    91     Elem *ans = freed_head_;
    92     freed_head_ = freed_head_->
tail;
    95     Elem *tmp = 
new Elem[allocate_block_size_];
    96     for (
size_t i = 0; 
i+1 < allocate_block_size_; 
i++)
    97       tmp[
i].tail = tmp+
i+1;
    98     tmp[allocate_block_size_-1].tail = NULL;
   100     allocated_.push_back(tmp);
   105 template<
class I, 
class T>
   109   size_t num_in_list = 0, num_allocated = 0;
   110   for (Elem *e = freed_head_; e != NULL; e = e->tail)
   112   for (
size_t i = 0; 
i < allocated_.size(); 
i++) {
   113     num_allocated += allocate_block_size_;
   114     delete[] allocated_[
i];
   116   if (num_in_list != num_allocated) {
   117     KALDI_WARN << 
"Possible memory leak: " << num_in_list
   118                << 
" != " << num_allocated
   119                << 
": you might have forgotten to call Delete on "   124 template<
class I, 
class T>
   126   size_t index = (
static_cast<size_t>(key) % hash_size_);
   127   HashBucket &bucket = buckets_[index];
   129   if (bucket.last_elem != NULL) {
   130     Elem *head = (bucket.prev_bucket == 
static_cast<size_t>(-1) ?
   132                   buckets_[bucket.prev_bucket].last_elem->tail),
   133          *tail = bucket.last_elem->
tail;
   134     for (Elem *e = head; e != tail; e = e->tail)
   135       if (e->key == key) 
return e;
   142   if (bucket.last_elem == NULL) {  
   145     if (bucket_list_tail_ == static_cast<size_t>(-1)) {
   151       buckets_[bucket_list_tail_].last_elem->tail = elem;
   154     bucket.last_elem = elem;
   155     bucket.prev_bucket = bucket_list_tail_;
   156     bucket_list_tail_ = index;
   160     elem->tail = bucket.last_elem->tail;
   161     bucket.last_elem->tail = elem;
   162     bucket.last_elem = elem;
   167 template<
class I, 
class T>
   169   size_t index = (
static_cast<size_t>(key) % hash_size_);
   170   HashBucket &bucket = buckets_[index];
   176   if (bucket.last_elem->key == key) {  
   177     elem->tail = bucket.last_elem->tail;
   178     bucket.last_elem->tail = elem;
   179     bucket.last_elem = elem;
   182   Elem *e = (bucket.prev_bucket == 
static_cast<size_t>(-1) ?
   183              list_head_ : buckets_[bucket.prev_bucket].last_elem->tail);
   185   while (e != bucket.last_elem->tail && e->key != key) e = e->tail;
   187   elem->tail = e->tail;
   194 #endif  // KALDI_UTIL_HASH_LIST_INL_H_ This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
 
Elem * Insert(I key, T val)
Insert inserts a new element into the hashtable/stored list. 
 
HashList()
Constructor takes no arguments. 
 
void SetSize(size_t sz)
SetSize tells the object how many hash buckets to allocate (should typically be at least twice the nu...
 
const Elem * GetList() const
Gives the head of the current list to the user. 
 
Elem * Clear()
Clears the hash and gives the head of the current list to the user; ownership is transferred to the u...
 
Elem * New()
This should probably not be needed to be called directly by the user. 
 
#define KALDI_ASSERT(cond)
 
void InsertMore(I key, T val)
Insert inserts another element with same key into the hashtable/ stored list. 
 
Elem * Find(I key)
Find tries to find this element in the current list using the hashtable. 
 
void Delete(Elem *e)
Think of this like delete().