55 for (
int i = 0; i < N; i++) {
56 Key key = rnd.
Next() % R;
57 if (keys.insert(key).second) {
62 for (
int i = 0; i < R; i++) {
89 for (
int i = 0; i < R; i++) {
94 std::set<Key>::iterator model_iter = keys.lower_bound(i);
95 for (
int j = 0; j < 3; j++) {
96 if (model_iter == keys.end()) {
114 for (std::set<Key>::reverse_iterator model_iter = keys.rbegin();
115 model_iter != keys.rend();
151 static const uint32_t K = 4;
153 static uint64_t
key(Key key) {
return (key >> 40); }
154 static uint64_t
gen(Key key) {
return (key >> 8) & 0xffffffffu; }
155 static uint64_t
hash(Key key) {
return key & 0xff; }
158 uint64_t data[2] = { k, g };
159 return Hash(reinterpret_cast<char*>(data),
sizeof(data), 0);
163 assert(
sizeof(Key) ==
sizeof(uint64_t));
165 assert(g <= 0xffffffffu);
166 return ((k << 40) | (g << 8) | (HashNumbers(k, g) & 0xff));
170 return hash(k) == (HashNumbers(key(k), gen(k)) & 0xff);
174 switch (rnd->
Next() % 10) {
189 port::AtomicPointer generation[K];
190 void Set(
int k, intptr_t v) {
191 generation[k].Release_Store(reinterpret_cast<void*>(v));
194 return reinterpret_cast<intptr_t
>(generation[k].Acquire_Load());
198 for (
int k = 0; k < K; k++) {
218 const uint32_t k = rnd->
Next() % K;
219 const intptr_t g = current_.
Get(k) + 1;
228 for (
int k = 0; k < K; k++) {
229 initial_state.
Set(k, current_.
Get(k));
232 Key pos = RandomTarget(rnd);
240 current = iter.
key();
243 ASSERT_LE(pos, current) <<
"should not go backwards";
247 while (pos < current) {
253 (gen(pos) > static_cast<Key>(initial_state.
Get(key(pos))))
254 ) <<
"key: " << key(pos)
255 <<
"; gen: " << gen(pos)
257 << initial_state.
Get(key(pos));
260 if (key(pos) < key(current)) {
261 pos =
MakeKey(key(pos) + 1, 0);
263 pos =
MakeKey(key(pos), gen(pos) + 1);
271 if (rnd->
Next() % 2) {
273 pos =
MakeKey(key(pos), gen(pos) + 1);
275 Key new_target = RandomTarget(rnd);
276 if (new_target > pos) {
278 iter.
Seek(new_target);
291 for (
int i = 0; i < 10000; i++) {
317 while (state_ != s) {
352 const int kSize = 1000;
353 for (
int i = 0; i < N; i++) {
354 if ((i % 100) == 0) {
355 fprintf(stderr,
"Run %d of %d\n", i, N);
360 for (
int i = 0; i < kSize; i++) {
376 int main(
int argc,
char** argv) {
static uint64_t HashNumbers(uint64_t k, uint64_t g)
void WriteStep(Random *rnd)
uint32_t Hash(const char *data, size_t n, uint32_t seed)
std::string MakeKey(unsigned int num)
void ReadStep(Random *rnd)
int operator()(const Key &a, const Key &b) const
SkipList< Key, Comparator > list_
static Key RandomTarget(Random *rnd)
void Set(int k, intptr_t v)
void Change(ReaderState s)
static Key MakeKey(uint64_t k, uint64_t g)
int main(int argc, char **argv)
void Seek(const Key &target)
TEST(AutoCompactTest, ReadAll)
bool Contains(const Key &key) const
static void ConcurrentReader(void *arg)
static void RunConcurrent(int run)
void Insert(const Key &key)
virtual void Schedule(void(*function)(void *arg), void *arg)=0
static uint64_t hash(Key key)
static uint64_t key(Key key)
static uint64_t gen(Key key)
port::AtomicPointer quit_flag_
static bool IsValidKey(Key k)