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

uint32_t symap_map ( Symap map,
const char *  sym 
)

Map a string to a symbol ID.

Note that 0 is never a valid symbol ID.

Definition at line 143 of file symap.c.

References SymapImpl::index, SymapImpl::size, symap_search(), and SymapImpl::symbols.

{
      bool           exact;
      const uint32_t index = symap_search(map, sym, &exact);
      if (exact) {
            assert(!strcmp(map->symbols[map->index[index] - 1], sym));
            return map->index[index];
      }

      const uint32_t id  = ++map->size;
      char* const    str = symap_strdup(sym);

      /* Append new symbol to symbols array */
      map->symbols = realloc(map->symbols, map->size * sizeof(char*));
      map->symbols[id - 1] = str;

      /* Insert new index element into sorted index */
      map->index = realloc(map->index, map->size * sizeof(uint32_t));
      if (index < map->size - 1) {
            memmove(map->index + index + 1,
                    map->index + index,
                    (map->size - index - 1) * sizeof(uint32_t));
      }

      map->index[index] = id;

      return id;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index