func ExampleBucket_PrefixItems() {
	bx, _ := buckets.Open(tempfile())
	defer os.Remove(bx.Path())
	defer bx.Close()

	// Create a new things bucket.
	things, _ := bx.New([]byte("things"))

	// Setup items to insert.
	items := []struct {
		Key, Value []byte
	}{
		{[]byte("A"), []byte("1")},   // `A` prefix match
		{[]byte("AA"), []byte("2")},  // match
		{[]byte("AAA"), []byte("3")}, // match
		{[]byte("AAB"), []byte("2")}, // match
		{[]byte("B"), []byte("O")},
		{[]byte("BA"), []byte("0")},
		{[]byte("BAA"), []byte("0")},
	}

	// Insert 'em.
	if err := things.Insert(items); err != nil {
		fmt.Printf("could not insert items in `things` bucket: %v\n", err)
	}

	// Now get items whose key starts with "A".
	prefix := []byte("A")

	results, err := things.PrefixItems(prefix)
	if err != nil {
		fmt.Printf("could not get items with prefix %q: %v\n", prefix, err)
	}

	for _, item := range results {
		fmt.Printf("%s -> %s\n", item.Key, item.Value)
	}
	// Output:
	// A -> 1
	// AA -> 2
	// AAA -> 3
	// AAB -> 2
}
// Show that we can get items for all keys with a given prefix.
Show that we can get items for all keys with a given prefix.
// Show that we can get items for all keys with a given prefix .
func ExampleBucket_PrefixItems() {
	bx, _ := buckets.Open(tempfile())
	defer os.Remove(bx.Path())
	defer bx.Close()
	things, _ := bx.New([]byte("things"))
	items := []struct {
		Key, Value []byte
	}{
		{[]byte("A"), []byte("1")},   
		{[]byte("AA"), []byte("2")},  
		{[]byte("AAA"), []byte("3")}, 
		{[]byte("AAB"), []byte("2")}, 
		{[]byte("B"), []byte("O")},
		{[]byte("BA"), []byte("0")},
		{[]byte("BAA"), []byte("0")},
	}
	if err := things.Insert(items); err != nil {
		fmt.Printf("could not insert items in `things` bucket: %v\n", err)
	}
	prefix := []byte("A")
	results, err := things.PrefixItems(prefix)
	if err != nil {
		fmt.Printf("could not get items with prefix %q: %v\n", prefix, err)
	}
	for _, item := range results {
		fmt.Printf("%s -> %s\n", item.Key, item.Value)
	}
}
func ExampleBucket_PrefixItems ( ) { bx , _ := buckets . Open ( tempfile ( ) ) defer os . Remove ( bx . Path ( ) ) defer bx . Close ( ) things , _ := bx . New ( [ ] byte ( " " ) ) items := [ ] struct { Key , Value [ ] byte } { { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , } if err := things . Insert ( items ) ; err != nil { fmt . Printf ( " \n " , err ) } prefix := [ ] byte ( " " ) results , err := things . PrefixItems ( prefix ) if err != nil { fmt . Printf ( " \n " , prefix , err ) } for _ , item := range results { fmt . Printf ( " \n " , item . Key , item . Value ) } }
Show that we can get items for all keys with a given prefix.
Show that we can get items for all keys with a given prefix .
// Create a new things bucket. // Setup items to insert. // `A` prefix match // match // match // match // Insert 'em. // Now get items whose key starts with "A". // Output: // A -> 1 // AA -> 2 // AAA -> 3 // AAB -> 2