Edge GlobalTable::uNode(NodeOp op, Edge arg0, Edge arg1) { if (_size == _maxSize) grow(_size + 1); assert(_size < _maxSize); uint32_t hashVal = hashInt32(op); hashCombine(hashVal, hashInt32(2)); hashCombine(hashVal, hashPtr(arg0)); hashCombine(hashVal, hashPtr(arg1)); size_t index = hashVal % _cap; if (!lookup(hashVal, op, arg0, arg1, index)) { _table[index].key = Edge(new (2) Node(op, arg0, arg1)); _table[index].hashVal = hashVal; ++_size; } return _table[index].key; }
void GlobalTable::remove(Edge e) { uint32_t hashVal = hashInt32(e->op()); hashCombine(hashVal, hashInt32(e->size())); for (size_t i = 0; i < e->size(); i++) hashCombine(hashVal, hashPtr((*e)[i])); size_t index = hashVal % _cap; if (lookup(index, e, index)) { _table[index].key = Edge((void*) NULL); --_size; } }
int main(int argc, char * argv[]) { size_t q = 3; size_t k = 4; typedef KarpRabinHash<> HashFunction; std::vector<std::unique_ptr<HashFunction> > hashPtr(q); for(size_t z = 0; z < hashPtr.size(); ++z) { std::unique_ptr<HashFunction> & ptr = hashPtr[z]; ptr.reset(new HashFunction(k, 12)); } std::string str = "ACGTAACGT"; for (size_t j = 0; j < k; j++) { for(size_t z = 0; z < hashPtr.size(); ++z) { std::unique_ptr<HashFunction> & ptr = hashPtr[z]; ptr->eat(str[j]); } } for (size_t i = 0;;i++) { std::cout << std::string(str.begin() + i, str.begin() + i + k); for(size_t z = 0; z < hashPtr.size(); ++z) { std::unique_ptr<HashFunction> & ptr = hashPtr[z]; std::cout << ' ' << ptr->hashvalue; } std::cout << std::endl; if (i + k < str.size()) { for(size_t z = 0; z < hashPtr.size(); ++z) { std::unique_ptr<HashFunction> & ptr = hashPtr[z]; ptr->update(str[i], str[i + k]); } } else { break; } } return 0; }
Edge GlobalTable::uNode(NodeOp op, const Vec<Edge>& args) { if (_size == _maxSize) grow(_size + 1); assert(_size < _maxSize); uint32_t hashVal = hashInt32(op); hashCombine(hashVal, hashInt32(args.size())); for (size_t i = 0; i < args.size(); i++) hashCombine(hashVal, hashPtr(args[i])); size_t index = hashVal % _cap; if (!lookup(hashVal, op, args, index)) { _table[index].key = Edge(new (args.size()) Node(op, args)); _table[index].hashVal = hashVal; ++_size; } return _table[index].key; }
//! Implements the interface for a UtlContainable unsigned OsMsg::hash() const { return hashPtr(this); }
unsigned int XmlRpcMethodContainer::hash() const { return hashPtr(mpUserData); }