-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5285fc
commit 12dc5fa
Showing
3 changed files
with
67 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cachekv_test | ||
|
||
import "crypto/rand" | ||
|
||
func randSlice(sliceSize int) []byte { | ||
bz := make([]byte, sliceSize) | ||
_, _ = rand.Read(bz) | ||
return bz | ||
} | ||
|
||
func incrementByteSlice(bz []byte) { | ||
for index := len(bz) - 1; index >= 0; index-- { | ||
if bz[index] < 255 { | ||
bz[index]++ | ||
break | ||
} else { | ||
bz[index] = 0 | ||
} | ||
} | ||
} | ||
|
||
// Generate many keys starting at startKey, and are in sequential order | ||
func generateSequentialKeys(startKey []byte, numKeys int) [][]byte { | ||
toReturn := make([][]byte, 0, numKeys) | ||
cur := make([]byte, len(startKey)) | ||
copy(cur, startKey) | ||
for i := 0; i < numKeys; i++ { | ||
newKey := make([]byte, len(startKey)) | ||
copy(newKey, cur) | ||
toReturn = append(toReturn, newKey) | ||
incrementByteSlice(cur) | ||
} | ||
return toReturn | ||
} | ||
|
||
// Generate many random, unsorted keys | ||
func generateRandomKeys(keySize int, numKeys int) [][]byte { | ||
toReturn := make([][]byte, 0, numKeys) | ||
for i := 0; i < numKeys; i++ { | ||
newKey := randSlice(keySize) | ||
toReturn = append(toReturn, newKey) | ||
} | ||
return toReturn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters