當前位置: 首頁>>代碼示例>>Golang>>正文


Golang KeyValue.Find方法代碼示例

本文整理匯總了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)
	}
}
開發者ID:jayvansantos,項目名稱:camlistore,代碼行數:25,代碼來源:kvtest.go

示例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
}
開發者ID:jayvansantos,項目名稱:camlistore,代碼行數:8,代碼來源:kvtest.go

示例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)
	}
}
開發者ID:ndarilek,項目名稱:camlistore,代碼行數:9,代碼來源:index_test.go

示例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)
}
開發者ID:rfistman,項目名稱:camlistore,代碼行數:11,代碼來源:index.go

示例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)
	}
}
開發者ID:camlistore,項目名稱:camlistore,代碼行數:47,代碼來源:kvtest.go

示例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)
	}
}
開發者ID:rfistman,項目名稱:camlistore,代碼行數:18,代碼來源:buffer_test.go


注:本文中的camlistore/org/pkg/sorted.KeyValue.Find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。