dragonfly/server/table.h
Roman Gershman ac2eb7d45c Adding expiry functionality.
1. Major refactoring
2. LICENSE is updated with commons clause.
3. Server is built as "dragonfly"
2021-12-20 11:42:55 +02:00

38 lines
847 B
C++

// Copyright 2021, Roman Gershman. All rights reserved.
// See LICENSE for licensing terms.
//
#pragma once
#include <absl/container/flat_hash_map.h>
namespace dfly {
struct MainValue {
std::string str;
MainValue() = default;
MainValue(std::string_view s) : str(s) {
}
bool HasExpire() const {
return has_expire_;
}
void SetExpire(bool b) {
has_expire_ = b;
}
private:
bool has_expire_ = false;
};
using MainTable = absl::flat_hash_map<std::string, MainValue>;
using ExpireTable = absl::flat_hash_map<std::string, uint64_t>;
/// Iterators are invalidated when new keys are added to the table or some entries are deleted.
/// Iterators are still valid if a different entry in the table was mutated.
using MainIterator = MainTable::iterator;
using ExpireIterator = ExpireTable::iterator;
} // namespace dfly