Logo Search packages:      
Sourcecode: jalv version File versions  Download package

static uint32_t symap_search ( const Symap map,
const char *  sym,
bool *  exact 
) [static]

Return the index into map->index (not the ID) corresponding to sym, or the index where a new entry for sym should be inserted.

Definition at line 94 of file symap.c.

References SymapImpl::index, SymapImpl::size, and SymapImpl::symbols.

Referenced by symap_map(), and symap_try_map().

{
      *exact = false;
      if (map->size == 0) {
            return 0;  // Empty map, insert at 0
      } else if (strcmp(map->symbols[map->index[map->size - 1] - 1], sym) < 0) {
            return map->size;  // Greater than last element, append
      }

      uint32_t lower = 0;
      uint32_t upper = map->size - 1;
      uint32_t i     = upper;
      int      cmp;

      while (upper >= lower) {
            i   = lower + ((upper - lower) / 2);
            cmp = strcmp(map->symbols[map->index[i] - 1], sym);

            if (cmp == 0) {
                  *exact = true;
                  return i;
            } else if (cmp > 0) {
                  if (i == 0) {
                        break;  // Avoid underflow
                  }
                  upper = i - 1;
            } else {
                  lower = i + 1;
            }
      }

      assert(strcmp(map->symbols[map->index[i] - 1], sym) > 0);
      return i;
}

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index