Exemple #1
0
  void extend(table* old) {
    table& old_table = *old;
    std::lock_guard<std::mutex> lock(extend_lock_);
    if (table_.load() != &old_table) { return; }

    std::vector<std::lock_guard<std::mutex>> lock_array;
    for (auto& slot_lock : lock_table_) {
      slot_lock.lock();
    }

    const size_t new_size = old_table.size * 2;
    std::unique_ptr<table> new_table_ptr(init_table(new_size, 0));
    table& new_table = *new_table_ptr;
    for (size_t i = 0; i < old_table.size; ++i) {
      kvp* target = old_table[i];
      while (target != nullptr) {
        const size_t new_hash = MurmurHash2A(&target->key, sizeof(int), 0);
        const size_t slot = new_hash % new_size;
        std::unique_ptr<kvp> entry(new kvp(target->key, target->value));

        kvp* orig = new_table[slot];
        new_table[slot] = entry.get();
        entry->next = orig;
        new_table.add_entry();
        entry.release();

        target = target->next;
      }
    }
    table_.store(new_table_ptr.release());

    for (auto& slot_lock : lock_table_) {
      slot_lock.unlock();
    }
  }
Exemple #2
0
int POIDB::CreateTable(const std::string& table)
{
    POIDB_Table_Map::iterator it = _table_map.find(table);
    if (it == _table_map.end())
    {
        POITablePtr new_table_ptr(new POITable());
        _table_map.insert(std::make_pair(table, new_table_ptr));

        LOG(INFO)<< "Create table " << table << " succeced";

        return 0;
    }
    LOG(INFO)<< "table " << table << " not exist";
    return 1;
}