示例#1
0
HashMap * pushTable(HashMap *table, Item *item)
{
    if (item == NULL)
    {
        return table;
    }
    
    Hash hashcode = hashCode(item -> key);
    
    int index = hashcode & (table->size - 1);
    Item *orItem = table->table[index];
    
    if (!orItem)
    {
        //put in head
        return _pushInHead(table, item, index);
    }else
    {
        //put in list
        return _pushInList(table, item, index);
    }
    
    
}
void test_hashCode() {
	Key key = {6900000, 10};

	assertLongEquals("Hash should eq ip", 6900000,
					 hashCode(&key));
}
 inline unsigned long int generateIdentifier( unsigned long int multiplier = HAMBURGER_NUMBER ){
   return hashCode( int_to_str((unsigned long int)(get_elapsed_runtime() * multiplier)) );
 }
ValueType HashMap<KeyType,ValueType>::get(KeyType key) const {
   Cell *cp = findCell(hashCode(key) % nBuckets, key);
   if (cp == NULL) return ValueType();
   return cp->value;
}
示例#5
0
void dbHashTable::insert(dbDatabase* db, oid_t hashId,
                         oid_t rowId, int type, int offs, size_t nRows)
{
    dbHashTable* hash = (dbHashTable*)db->get(hashId);
    int keylen = keySize[type];
    byte* record = db->get(rowId);
    byte* key = record + offs;
    if (type == dbField::tpString) {
        keylen = ((dbVarying*)key)->size - 1;
        key = record + ((dbVarying*)key)->offs;
    }
    unsigned hashkey = hashCode(key, keylen);
    size_t size = hash->size;
    oid_t pageId = hash->page;
    if (size < nRows && hash->used*3/2 > size) {
        int nPages = (size+1) / dbIdsPerPage;
        size = (size+1)*2-1;
        oid_t newPageId = db->allocateId((size+1) / dbIdsPerPage);
        offs_t pos = db->allocate((size+1)*sizeof(oid_t));
        assert((pos & (dbPageSize-1)) == 0);
        memset(db->baseAddr + pos, 0, (size+1)*sizeof(oid_t));
        hash = (dbHashTable*)db->put(hashId);
        hash->size = size;
        hash->page = newPageId;
        size_t used = 0;
        while (--nPages >= 0) {
            for (size_t i = 0; i < dbIdsPerPage; i++) {
                oid_t itemId = ((oid_t*)db->get(pageId))[i];
                while (itemId != 0) {
                    dbHashTableItem* item = (dbHashTableItem*)db->get(itemId);
                    oid_t nextId = item->next;
                    unsigned h = item->hash % size;
                    oid_t* tab = (oid_t*)(db->baseAddr + pos);
                    if (item->next != tab[h]) {
                        item = (dbHashTableItem*)db->put(itemId);
                        tab = (oid_t*)(db->baseAddr + pos);
                        item->next = tab[h];
                    }
                    if (tab[h] == 0) {
                        used += 1;
                    }
                    tab[h] = itemId;
                    itemId = nextId;
                }
            }
            db->freeObject(pageId++);
        }
        ((dbHashTable*)db->get(hashId))->used = used;
        pageId = newPageId;
        for (nPages = (size+1)/dbIdsPerPage; --nPages >= 0; pos += dbPageSize) {
            db->currIndex[newPageId++] = pos + dbPageObjectMarker;
        }
    }
    oid_t itemId = db->allocateObject(dbHashTableItemMarker);
    unsigned h = hashkey % size;
    oid_t* ptr = (oid_t*)db->put(pageId + h/dbIdsPerPage) + h%dbIdsPerPage;
    dbHashTableItem* item = (dbHashTableItem*)db->get(itemId);
    item->record = rowId;
    item->hash = hashkey;
    item->next = *ptr;
    *ptr = itemId;
    if (item->next == 0) {
        ((dbHashTable*)db->get(hashId))->used += 1;
        db->file.markAsDirty(db->currIndex[hashId] & ~dbInternalObjectMarker, sizeof(dbHashTable));
        ((dbHashTable*)db->put(hashId))->used += 1;
    }
}
示例#6
0
int32_t MiscUtils::hashCode(const uint8_t* array, int32_t start, int32_t end) {
    return hashCode(array + start, array + end, hashNumeric<uint8_t>);
}
示例#7
0
		
      //wrap around the table
      hashIndex %= SIZE;
   }
	
   hashArray[hashIndex] = insertItem;
   items++;
}

struct DataItem* delete(struct DataItem* item) {
   int hashIndex;
   int key;
   key = item->key;

   //get the hash 
   hashIndex = hashCode(key);

   //move in array until an empty
   while(hashArray[hashIndex] != NULL) {
	
      if(hashArray[hashIndex]->key == key) {
         struct DataItem* temp = hashArray[hashIndex]; 
			
         //assign a dummy item at deleted position
         hashArray[hashIndex] = dummyItem; 
         items--;
         return temp;
      }
		
      //go to next cell
      ++hashIndex;
示例#8
0
ValueType HashMap<KeyType,ValueType>::get(KeyType key) const {
   Cell *cp = findCell(hashCode(key) % nBuckets, key);
   if (cp == NULL) error("get: no value for key");
   return cp->value;
}
 inline unsigned long int setIdentifier( const char* newIdentifier){
   return Base::setIdentifier( newIdentifier ? hashCode(newIdentifier) : NULL );
 }
示例#10
0
size_t Variant::hashCode() const {
	switch (mType) {
	case Null:
		return mType;
	case Bool:
		return hashCode(mType, &mValue.boolValue, sizeof(mValue.boolValue));
	case Byte:
		return hashCode(mType, &mValue.byteValue, sizeof(mValue.byteValue));
	case Char:
		return hashCode(mType, &mValue.charValue, sizeof(mValue.charValue));
	case Short:
		return hashCode(mType, &mValue.shortValue, sizeof(mValue.shortValue));
	case UnsignedShort:
		return hashCode(mType, &mValue.unsignedShortValue, sizeof(mValue.unsignedShortValue));
	case Int:
		return hashCode(mType, &mValue.intValue, sizeof(mValue.intValue));
	case UnsignedInt:
		return hashCode(mType, &mValue.unsignedIntValue, sizeof(mValue.unsignedIntValue));
	case Long:
		return hashCode(mType, &mValue.longValue, sizeof(mValue.longValue));
	case UnsignedLong:
		return hashCode(mType, &mValue.unsignedLongValue, sizeof(mValue.unsignedLongValue));
	case Float:
		return hashCode(mType, &mValue.floatValue, sizeof(mValue.floatValue));
	case Double:
		return hashCode(mType, &mValue.doubleValue, sizeof(mValue.doubleValue));
	case String:
	case StringSet:
	case StringArrayList:
	case IntegerArrayList:
	case Object:
		if (mValue.object != nullptr) {
			return mValue.object->hashCode();
		} else {
			return 0;
		}
		break;
	case Binder:
		if (mValue.binder != nullptr) {
			return mValue.binder->hashCode();
		} else {
			return 0;
		}
		break;
	default:
		return 0;
		break;
	}
}
示例#11
0
 int Data::getPartitionHash() const {
     if (hasPartitionHash()) {
         return Bits::readIntB(*data, Data::PARTITION_HASH_OFFSET);
     }
     return hashCode();
 }
示例#12
0
/***********************************************************************
 * Handler implementation
 **********************************************************************/
bool Pothos::RemoteHandler::runHandlerOnce(std::istream &is, std::ostream &os)
{
    bool done = false;

    //deserialize the request
    const auto reqArgs = recvDatagram(is);

    //process the request and form the reply
    Pothos::ObjectKwargs replyArgs;
    replyArgs["tid"] = reqArgs.at("tid");
    POTHOS_EXCEPTION_TRY
    {
        const auto &action = reqArgs.at("action").extract<std::string>();
        if (action == "RemoteProxyEnvironment")
        {
            Pothos::ProxyEnvironmentArgs envArgs;
            for (const auto &entry : reqArgs)
            {
                if (entry.second.type() != typeid(std::string)) continue;
                envArgs[entry.first] = entry.second.extract<std::string>();
            }
            const auto &name = reqArgs.at("name").extract<std::string>();
            auto env = Pothos::ProxyEnvironment::make(name, envArgs);
            replyArgs["envID"] = getNewObjectId(Pothos::Object(env));

            //a unique process ID for this server
            const auto info = Pothos::System::HostInfo::get();
            replyArgs["upid"] = Pothos::Object(Pothos::ProxyEnvironment::getLocalUniquePid());
            replyArgs["nodeId"] = Pothos::Object(info.nodeId);
            replyArgs["peerAddr"] = Pothos::Object(_peerAddr);
        }
        else if (action == "~RemoteProxyEnvironment")
        {
            removeObjectAtId(reqArgs.at("envID"));
            done = true;
        }
        else if (action == "findProxy")
        {
            auto env = getObjectAtId(reqArgs.at("envID")).extract<Pothos::ProxyEnvironment::Sptr>();
            auto proxy = env->findProxy(reqArgs.at("name").extract<std::string>());
            replyArgs["handleID"] = getNewObjectId(Pothos::Object(proxy));
        }
        else if (action == "convertObjectToProxy")
        {
            auto env = getObjectAtId(reqArgs.at("envID")).extract<Pothos::ProxyEnvironment::Sptr>();
            auto proxy = env->convertObjectToProxy(reqArgs.at("local"));
            replyArgs["handleID"] = getNewObjectId(Pothos::Object(proxy));
        }
        else if (action == "convertProxyToObject")
        {
            auto env = getObjectAtId(reqArgs.at("envID")).extract<Pothos::ProxyEnvironment::Sptr>();
            auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>();
            auto local = env->convertProxyToObject(proxy);
            replyArgs["local"] = local;
        }
        else if (action == "~RemoteProxyHandle")
        {
            removeObjectAtId(reqArgs.at("handleID"));
        }
        else if (action == "call")
        {
            auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>();

            //load the args
            std::vector<Pothos::Proxy> args;
            size_t argNo = 0;
            while (true)
            {
                auto it = reqArgs.find(std::to_string(argNo++));
                if (it == reqArgs.end()) break;
                args.push_back(getObjectAtId(it->second).extract<Pothos::Proxy>());
            }

            //make the call
            try
            {
                const auto &name = reqArgs.at("name").extract<std::string>();
                auto result = proxy.getHandle()->call(name, args.data(), args.size());
                replyArgs["handleID"] = getNewObjectId(Pothos::Object(result));
            }
            catch (const Pothos::ProxyExceptionMessage &ex)
            {
                replyArgs["message"] = Pothos::Object(ex.message());
            }
        }
        else if (action == "compareTo")
        {
            auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>();
            auto other = getObjectAtId(reqArgs.at("otherID")).extract<Pothos::Proxy>();
            replyArgs["result"] = Pothos::Object(proxy.compareTo(other));
        }
        else if (action == "hashCode")
        {
            auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>();
            replyArgs["result"] = Pothos::Object(proxy.hashCode());
        }
        else if (action == "toString")
        {
            auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>();
            replyArgs["result"] = Pothos::Object(proxy.toString());
        }
        else if (action == "getClassName")
        {
            auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>();
            replyArgs["result"] = Pothos::Object(proxy.getClassName());
        }
        else
        {
            poco_bugcheck_msg(action.c_str());
        }
    }
    POTHOS_EXCEPTION_CATCH(const Pothos::Exception &ex)
    {
        replyArgs["errorMsg"] = Pothos::Object(ex.displayText());
    }
int * Table::lookup(const string &key) {

  return addressOf(hashTable[hashCode(key)],key);

}
bool Table::remove(const string &key) {

  return deleteEntry(hashTable[hashCode(key)],key);

}
示例#15
0
 int Data::getPartitionHash() const {
     if (hasPartitionHash()) {
         return Bits::readIntB(*data, data->size() - Bits::INT_SIZE_IN_BYTES);
     }
     return hashCode();
 }
示例#16
0
void testForEach()
{
    static std::string ar[] = {"one", "another", "last"};
    BOOST_FOREACH(const std::string& s, ar)
    {
        std::cout << s << std::endl;
    }

    std::string s = "Hello0";
  boost::crc_32_type result;
  result.process_bytes(s.data(), s.length());
  unsigned tag = result.checksum();
  std::cout << tag << std::endl;
  
  std::cout << abs(hashCode("32521001fffddf4425643d3e7fe")) << std::endl;
  std::cout << hashCode("1001") << std::endl;
  std::cout << hashCode("1001") << std::endl;

  //std::cout << boost::lexical_cast<int32_t>( "3669185006" );

  unsigned int nId = 0;
  unsigned int progId = 0;
  std::stringstream ss;
  ss << std::hex << "A";
  ss >> progId;
  ss.clear();
  ss << std::hex << "B";
  ss >> nId;
  std::cout << progId << std::endl;
  std::cout << nId << std::endl;
示例#17
0
int hashCode(const IntRange& r) {
    return hashCode(r.min(), r.max());
}
示例#18
0
int hashCode(const GridLocation& loc) {
    return hashCode(loc.row, loc.col);
}
示例#19
0
bool HashMap<KeyType,ValueType>::containsKey(KeyType key) const {
   return findCell(hashCode(key) % nBuckets, key) != NULL;
}
示例#20
0
 jint JBoolean::hashCode(){
     return hashCode(value->get());
 }
示例#21
0
文件: JChar.cpp 项目: jeffedlund/rpc
 jint JChar::hashCode(){
     return hashCode(value->get());
 }
int hashCode(void* key) {
    return hashCode(reinterpret_cast<long>(key));
}
示例#23
0
文件: JByte.cpp 项目: jeffedlund/rpc
 jint JByte::hashCode(){
     return hashCode(value->get());
 }
示例#24
0
/*
 * Hash code function to make it possible to store arcs in a hash set/map.
 */
int hashCode(TBEdge e) {
    return (hashCode(e.start) + kLargePrime * hashCode(e.end)) & kHashMask;
}
示例#25
0
int hashCode(const Complex& c) {
    return hashCode(c.real(), c.imag());
}
示例#26
0
int hashCode(const Point& pt) {
    return hashCode(pt.getX(), pt.getY());
}