Code Monkey home page Code Monkey logo

libwxfreq's Issues

GetValueForWrite函数写入多阶Hash表操作可能有误

问题在如下注释:

`int MultiHashBase<Key, Value>::GetValueForWrite(const KeyType &input_key,
ValueType *&value) {
int ret = enMultiHashBucketFull;
ValueType * read_value_ptr;
ret = GetValueForRead(input_key, read_value_ptr);
if (ret == enMultiHashOK) {
value = read_value_ptr;
AfterFindWriteItem(*value);
return ret;
}

size_t offset = 0;
unsigned int find_level = 0;
ret = enMultiHashBucketFull;
size_t hash_key = HashKey(input_key);
for (find_level = 0; find_level < max_level_; find_level++) {
size_t index = hash_key % size_meta_[find_level];
KeyType* key_in_mem =
reinterpret_cast<KeyType >(shm_mem_base_ + offset + (item_size_ * index));
ValueType
value_in_mem = reinterpret_cast<ValueType *>(
reinterpret_cast<char *>(key_in_mem) + sizeof(KeyType));

uint32_t timestamp = 0;
if (IsEmpty(*key_in_mem, *value_in_mem) == true) {
  if (EmptyOccupy(input_key, *key_in_mem) == true) {
    memset(reinterpret_cast<void *>(value_in_mem), 0 , sizeof(ValueType));
    ret = enMultiHashOK;
    value = value_in_mem;
    break;
  }
  continue;  

//不能占据位置时,continue会跳到下一层的level, 但offset没有更新计算, 这个continue会不会有问题?

} else if (IsExpired(*key_in_mem, *value_in_mem, &timestamp) == true) {
  if (ExpiredOccupy(input_key, *key_in_mem, *value_in_mem, &timestamp) == true) {
    memset(reinterpret_cast<void *>(value_in_mem), 0 , sizeof(ValueType));
    ret = enMultiHashOK;
    value = value_in_mem;
    break;
  }
  continue; 

//不能占据位置时,continue会跳到下一层的level, 但offset没有更新计算, 这个continue会不会有问题?

}
offset += size_meta_[find_level] * item_size_;

}
if (ret == enMultiHashOK) {
gLog("[%s][%d]: level %d hash %llu\n", FILE, LINE,
find_level, hash_key);
} else {
gLog("[%s][%d]: not found hash %llu\n", FILE, LINE, hash_key);
}
return ret;
}`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.