Symbol* SymbolTable::lookup(int index, const char* name,
                              int len, unsigned int hash) {
  int count = 0;
  for (HashtableEntry<Symbol*, mtSymbol>* e = bucket(index); e != NULL; e = e->next()) {
    count++;  // count all entries in this bucket, not just ones with same hash
    if (e->hash() == hash) {
      Symbol* sym = e->literal();
      if (sym->equals(name, len)) {
        // something is referencing this symbol now.
        sym->increment_refcount();
        return sym;
      }
    }
  }
  // If the bucket size is too deep check if this hash code is insufficient.
  if (count >= BasicHashtable<mtSymbol>::rehash_count && !needs_rehashing()) {
    _needs_rehashing = check_rehash_table(count);
  }
  return NULL;
}
Beispiel #2
0
float Simulation::calcSymbolsBinding(SimObj* obj,
                                    int symTable,
                                    gbULINT symID,
                                    Symbol* symbol,
                                    BindingType type)
{
    SymbolTable* table = obj->getSymbolTable(symTable);

    if (table == NULL)
    {
        return 0.0f;
    }

    Symbol* sym = table->getSymbol(symID);

    if (sym == NULL)
    {
        return 0.0f;
    }

    float binding = 0.0f;
    
    switch (type)
    {
    case BINDING_EQUALS:
        if (sym->equals(symbol))
        {
            binding = 1.0f;
        }
        break;
    case BINDING_PROXIMITY:
        binding = sym->proximity(symbol);
        break;
    }

    return binding;
}