MCPcopy Create free account
hub / github.com/ElementsProject/elements / PickRandomKey

Method PickRandomKey

src/leveldb/table/table_test.cc:578–603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

576 }
577
578 std::string PickRandomKey(Random* rnd, const std::vector<std::string>& keys) {
579 if (keys.empty()) {
580 return "foo";
581 } else {
582 const int index = rnd->Uniform(keys.size());
583 std::string result = keys[index];
584 switch (rnd->Uniform(3)) {
585 case 0:
586 // Return an existing key
587 break;
588 case 1: {
589 // Attempt to return something smaller than an existing key
590 if (!result.empty() && result[result.size() - 1] > '\0') {
591 result[result.size() - 1]--;
592 }
593 break;
594 }
595 case 2: {
596 // Return something larger than an existing key
597 Increment(options_.comparator, &result);
598 break;
599 }
600 }
601 return result;
602 }
603 }
604
605 // Returns nullptr if not running against a DB
606 DB* db() const { return constructor_->db(); }

Callers

nothing calls this directly

Calls 4

IncrementFunction · 0.85
UniformMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected