本文整理汇总了C++中HashNode类的典型用法代码示例。如果您正苦于以下问题:C++ HashNode类的具体用法?C++ HashNode怎么用?C++ HashNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HashNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RefreshVertices
void HashGraph::RefreshVertices(unsigned minCount)
{
#pragma omp parallel for
for (int64 i = 0; i < (int64)table_size; ++i)
{
HashNode *node = table[i];
HashNode *prev = NULL;
while (node != NULL)
{
if (node->IsDead() || node->Count() < minCount)
{
#pragma omp atomic
--num_nodes;
if (prev == NULL)
{
table[i] = node->next;
FreeNode(node, omp_get_thread_num());
node = table[i];
}
else
{
prev->next = node->next;
FreeNode(node, omp_get_thread_num());
node = prev->next;
}
}
else
{
node->ClearStatus();
prev = node;
node = prev->next;
}
}
}
}
示例2: resize
void resize() {
int new_length = 4;
while(new_length < elems_) {
new_length <<= 1;
}
HashNode** new_list = new HashNode*[new_length];
memset(new_list, 0, sizeof(new_list[0]) * new_length);
int count = 0;
for(int i=0; i<length_; ++i) {
HashNode* now = list_[i];
while(now != NULL) {
HashNode* next = now->next_hash;
Slice key = now->key();
int hash = now->hash;
HashNode** ptr = &new_list[hash & (new_length - 1)];
now->next_hash = *ptr;
*ptr = now;
now = next;
count++;
}
}
assert(elems_ == count);
delete[] list_;
list_ = new_list;
length_ = new_length;
}
示例3: ClearGraph
void HashGraph::ClearGraph()
{
for (unsigned i = 0; i < table_size; ++i)
{
for (HashNode *node = table[i]; node != NULL; node = node->next)
{
node->Clear();
node->SetCount(1);
}
}
num_edges = 0;
}
示例4: AddAllEdges
void HashGraph::AddAllEdges()
{
num_edges = 0;
#pragma omp parallel for
for (int64 i = 0; i < (int64)table_size; ++i)
{
for (HashNode *node = table[i]; node; node = node->next)
{
node->SetInEdges(15);
node->SetOutEdges(15);
}
}
}
示例5: evict
void GrCCPathCache::evict(const GrCCPathCache::Key& key, GrCCPathCacheEntry* entry) {
if (!entry) {
HashNode* node = fHashTable.find(key);
SkASSERT(node);
entry = node->entry();
}
SkASSERT(*entry->fCacheKey == key);
SkASSERT(!entry->hasBeenEvicted());
entry->fCacheKey->markShouldUnregisterFromPath(); // Unregister the path listener.
entry->releaseCachedAtlas(this);
fLRU.remove(entry);
fHashTable.remove(key);
}
示例6: AverageCoverage
double HashGraph::AverageCoverage()
{
long long sum = 0;
uint64 valid = 0;
for (int64 i = 0; i < table_size; ++i)
{
for (HashNode *node = table[i]; node; node = node->next)
{
sum += node->Count();
++valid;
}
}
return 1.0 * sum / valid;
}
示例7: findPosition
int CTECHashTable<Type>:: findPosition(HashNode<Type> currentNode){
int position = 0;
position = currentNode.getKey()%capacity;
return position;
}
示例8: MedianCoverage
double HashGraph::MedianCoverage()
{
vector<int> v;
v.reserve(num_nodes);
for (int64 i = 0; i < table_size; ++i)
{
for (HashNode *node = table[i]; node; node = node->next)
{
v.push_back(node->Count());
}
}
nth_element(v.begin(), v.begin() + v.size()/2, v.end());
return *(v.begin() + v.size()/2);
}
示例9: insert
HashNode* insert(const Slice& key, int& hit_id, int& rep_id) {
HashNode* e = reinterpret_cast<HashNode*>(malloc(sizeof(HashNode) - 1 + key.size()));
e->key_length = key.size();
e->hash = hash_slice(key);
memcpy(e->key_data, key.data(), key.size());
lru_append(e);
HashNode* old = table_.insert(e);
if(old != NULL) {
//命中缓存
e->cache_id = old->cache_id;
hit_id = e->cache_id;
rep_id = -1;
lru_remove(old);
lru_release(old);
//update hit ratio
hit_cnt++;
}
else {
//没有命中缓存
hit_id = -1;
//如果当前的缓存数量超过capacity,把lru_后面的那个缓存单元淘汰掉
if(table_.size() > capacity_) {
HashNode* cursor = lru_.next;
lru_remove(cursor);
table_.remove(cursor->key(), cursor->hash);
e->cache_id = cursor->cache_id;
lru_release(cursor);
}
else {
e->cache_id = last_id++; //TODO 会无限增长?
}
rep_id = e->cache_id;
//update hit ratio
set_cnt++;
}
return e;
}
示例10: findPosition
long HashTable<Type> :: findPosition(Type data)
{
long insertedPosition;
unsigned long address =(long)&data;
insertedPosition = address % capacity;
HashNode<Type>* indexPointer = front;
for (long index = 0; index < insertedPosition; index++)
{
indexPointer = indexPointer->getNode();
}
if (indexPointer->hasStuffed())
{
insertedPosition = handleCollision(data, insertedPosition);
}
return insertedPosition;
}
示例11: findPosition
int HashTable<Type> :: findPosition(HashNode<Type> currentNode)
{
//We are going "hash" the key of the HashNode to find its value.
int position = 0;
position = currentNode.getKey() % capacity;
return position;
}
示例12:
int CTECHashTable<Type>::findTablePosition(HashNode<Type> currentNode)
{
//We are going to "hash" the key of the hashnode to find its storage spot.
int position = 0;
position = currentNode.getKey() % tableCapacity;
return position;
}
示例13: RefreshEdges
void HashGraph::RefreshEdges()
{
num_edges = 0;
#pragma omp parallel for
for (int64 i = 0; i < (int64)table_size; ++i)
{
for (HashNode *node = table[i]; node; node = node->next)
{
KmerNodeAdapter curr(node);
for (int strand = 0; strand < 2; ++strand)
{
Kmer kmer;
curr.GetKmer(kmer);
unsigned edges = curr.OutEdges();
for (int x = 0; x < 4; ++x)
{
if (edges & (1 << x))
{
Kmer next = kmer;
next.AddRight(x);
if (GetNode(next) == NULL)
curr.RemoveOutEdge(x);
else
{
#pragma omp atomic
++num_edges;
}
}
}
curr.ReverseComplement();
}
if (node->kmer.IsPalindrome())
{
unsigned edges = node->InEdges() | node->OutEdges();
node->SetInEdges(edges);
node->SetOutEdges(edges);
}
}
}
num_edges >>= 1;
}
示例14: contains
bool CTECHashTable<Type>:: contains(HashNode<Type> currentNode){
bool isInTable = false;
int possibleLocation = findPosition(currentNode);
while(internalStorage[possibleLocation] != nullptr && !isInTable){
if(internalStorage[possibleLocation] == currentNode.getValue()){
isInTable = true;
}
possibleLocation = (possibleLocation + 1) % capacity;
}
return isInTable;
}
示例15: remove
bool CTECHashTable<Type>:: remove(HashNode<Type> currentNode){
bool hasBeenRemoved = false;
int possibleLocation = findPosition(currentNode);
if(contains(currentNode)){
while(internalStorage[possibleLocation] != nullptr && !hasBeenRemoved){
if(internalStorage[possibleLocation] == currentNode.getValue()){
hasBeenRemoved = true;
internalStorage[possibleLocation] = nullptr;
}
possibleLocation = (possibleLocation + 1) % capacity;
}
}
return hasBeenRemoved;
}