本文整理匯總了Golang中camlistore/org/pkg/sorted.KeyValue.Find方法的典型用法代碼示例。如果您正苦於以下問題:Golang KeyValue.Find方法的具體用法?Golang KeyValue.Find怎麽用?Golang KeyValue.Find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類camlistore/org/pkg/sorted.KeyValue
的用法示例。
在下文中一共展示了KeyValue.Find方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: testEnumerate
func testEnumerate(t *testing.T, kv sorted.KeyValue, start, end string, want ...string) {
var got []string
it := kv.Find(start, end)
for it.Next() {
key, val := it.Key(), it.Value()
keyb, valb := it.KeyBytes(), it.ValueBytes()
if key != string(keyb) {
t.Errorf("Key and KeyBytes disagree: %q vs %q", key, keyb)
}
if val != string(valb) {
t.Errorf("Value and ValueBytes disagree: %q vs %q", val, valb)
}
if key+"v" != val {
t.Errorf("iterator returned unexpected pair for test: %q, %q", key, val)
}
got = append(got, val)
}
err := it.Close()
if err != nil {
t.Errorf("for enumerate of (%q, %q), Close error: %v", start, end, err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("for enumerate of (%q, %q), got: %q; want %q", start, end, got, want)
}
}
示例2: isEmpty
func isEmpty(t *testing.T, kv sorted.KeyValue) bool {
it := kv.Find("", "")
hasRow := it.Next()
if err := it.Close(); err != nil {
t.Fatalf("Error closing iterator while testing for emptiness: %v", err)
}
return !hasRow
}
示例3: foreachSorted
func foreachSorted(t *testing.T, s sorted.KeyValue, fn func(string, string)) {
it := s.Find("", "")
for it.Next() {
fn(it.Key(), it.Value())
}
if err := it.Close(); err != nil {
t.Fatal(err)
}
}
示例4: queryPrefixString
func queryPrefixString(s sorted.KeyValue, prefix string) sorted.Iterator {
if prefix == "" {
return s.Find("", "")
}
lastByte := prefix[len(prefix)-1]
if lastByte == 0xff {
panic("unsupported query prefix ending in 0xff")
}
end := prefix[:len(prefix)-1] + string(lastByte+1)
return s.Find(prefix, end)
}
示例5: testInsertLarge
func testInsertLarge(t *testing.T, kv sorted.KeyValue) {
largeKey := make([]byte, sorted.MaxKeySize-1)
// setting all the bytes because postgres whines about an invalid byte sequence
// otherwise
for k, _ := range largeKey {
largeKey[k] = 'A'
}
largeKey[sorted.MaxKeySize-2] = 'B'
largeValue := make([]byte, sorted.MaxValueSize-1)
for k, _ := range largeValue {
largeValue[k] = 'A'
}
largeValue[sorted.MaxValueSize-2] = 'B'
// insert with large key
if err := kv.Set(string(largeKey), "whatever"); err != nil {
t.Fatalf("Insertion of large key failed: %v", err)
}
// and verify we can get it back, i.e. that the key hasn't been truncated.
it := kv.Find(string(largeKey), "")
if !it.Next() || it.Key() != string(largeKey) || it.Value() != "whatever" {
it.Close()
t.Fatalf("Find(largeKey) = %q, %q; want %q, %q", it.Key(), it.Value(), largeKey, "whatever")
}
it.Close()
// insert with large value
if err := kv.Set("whatever", string(largeValue)); err != nil {
t.Fatalf("Insertion of large value failed: %v", err)
}
// and verify we can get it back, i.e. that the value hasn't been truncated.
if v, err := kv.Get("whatever"); err != nil || v != string(largeValue) {
t.Fatalf("get(\"whatever\") = %q, %v; want %q", v, err, largeValue)
}
// insert with large key and large value
if err := kv.Set(string(largeKey), string(largeValue)); err != nil {
t.Fatalf("Insertion of large key and value failed: %v", err)
}
// and verify we can get them back
it = kv.Find(string(largeKey), "")
defer it.Close()
if !it.Next() || it.Key() != string(largeKey) || it.Value() != string(largeValue) {
t.Fatalf("Find(largeKey) = %q, %q; want %q, %q", it.Key(), it.Value(), largeKey, largeValue)
}
}
示例6: check
func check(t *testing.T, kv sorted.KeyValue, prefix string, want []mod) {
it := kv.Find("", "")
for i, m := range want {
if !it.Next() {
t.Fatalf("%v: unexpected it.Next == false on iteration %d", prefix, i)
}
if k, v := it.Key(), it.Value(); k != m.key || v != m.value {
t.Errorf("%v: got key == %q value == %q, want key == %q value == %q on iteration %d",
prefix, k, v, m.key, m.value, i)
}
}
if it.Next() {
t.Errorf("%v: unexpected it.Next == true after complete iteration", prefix)
}
if err := it.Close(); err != nil {
t.Errorf("%v: error closing iterator: %v", prefix, err)
}
}