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

	// Delete any existing bucket named "years".
	bx.Delete([]byte("years"))

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

	// Setup items to insert in `years` bucket
	items := []struct {
		Key, Value []byte
	}{
		{[]byte("1970"), []byte("70")},
		{[]byte("1975"), []byte("75")},
		{[]byte("1980"), []byte("80")},
		{[]byte("1985"), []byte("85")},
		{[]byte("1990"), []byte("90")}, // min = 1990
		{[]byte("1995"), []byte("95")}, // min < 1995 < max
		{[]byte("2000"), []byte("00")}, // max = 2000
		{[]byte("2005"), []byte("05")},
		{[]byte("2010"), []byte("10")},
	}

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

	// Time range to map over: 1990 <= key <= 2000.
	min := []byte("1990")
	max := []byte("2000")

	// Setup slice of items to collect results.
	type item struct {
		Key, Value []byte
	}
	results := []item{}

	// Anon func to map over matched keys.
	do := func(k, v []byte) error {
		results = append(results, item{k, v})
		return nil
	}

	if err := years.MapRange(do, min, max); err != nil {
		fmt.Printf("could not map items within range: %v\n", err)
	}

	for _, item := range results {
		fmt.Printf("%s -> %s\n", item.Key, item.Value)
	}
	// Output:
	// 1990 -> 90
	// 1995 -> 95
	// 2000 -> 00
}
// Show that we can apply a function to the k/v pairs
// of keys within a given range.
Show that we can apply a function to the k/v pairs
of keys within a given range.
// Show that we can apply a function to the k / v pairs // of keys within a given range .
func ExampleBucket_MapRange() {
	bx, _ := buckets.Open(tempfile())
	defer os.Remove(bx.Path())
	defer bx.Close()
	bx.Delete([]byte("years"))
	years, _ := bx.New([]byte("years"))
	items := []struct {
		Key, Value []byte
	}{
		{[]byte("1970"), []byte("70")},
		{[]byte("1975"), []byte("75")},
		{[]byte("1980"), []byte("80")},
		{[]byte("1985"), []byte("85")},
		{[]byte("1990"), []byte("90")}, 
		{[]byte("1995"), []byte("95")}, 
		{[]byte("2000"), []byte("00")}, 
		{[]byte("2005"), []byte("05")},
		{[]byte("2010"), []byte("10")},
	}
	if err := years.Insert(items); err != nil {
		fmt.Printf("could not insert items in `years` bucket: %v\n", err)
	}
	min := []byte("1990")
	max := []byte("2000")
	type item struct {
		Key, Value []byte
	}
	results := []item{}
	do := func(k, v []byte) error {
		results = append(results, item{k, v})
		return nil
	}
	if err := years.MapRange(do, min, max); err != nil {
		fmt.Printf("could not map items within range: %v\n", err)
	}
	for _, item := range results {
		fmt.Printf("%s -> %s\n", item.Key, item.Value)
	}
}
func ExampleBucket_MapRange ( ) { bx , _ := buckets . Open ( tempfile ( ) ) defer os . Remove ( bx . Path ( ) ) defer bx . Close ( ) bx . Delete ( [ ] byte ( " " ) ) years , _ := bx . New ( [ ] byte ( " " ) ) items := [ ] struct { Key , Value [ ] byte } { { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , { [ ] byte ( " " ) , [ ] byte ( " " ) } , } if err := years . Insert ( items ) ; err != nil { fmt . Printf ( " \n " , err ) } min := [ ] byte ( " " ) max := [ ] byte ( " " ) type item struct { Key , Value [ ] byte } results := [ ] item { } do := func ( k , v [ ] byte ) error { results = append ( results , item { k , v } ) return nil } if err := years . MapRange ( do , min , max ) ; err != nil { fmt . Printf ( " \n " , err ) } for _ , item := range results { fmt . Printf ( " \n " , item . Key , item . Value ) } }
Show that we can apply a function to the k/v pairs
of keys within a given range.
Show that we can apply a function to the k / v pairs of keys within a given range .
// Delete any existing bucket named "years". // Create a new bucket named "years". // Setup items to insert in `years` bucket // min = 1990 // min < 1995 < max // max = 2000 // Insert 'em. // Time range to map over: 1990 <= key <= 2000. // Setup slice of items to collect results. // Anon func to map over matched keys. // Output: // 1990 -> 90 // 1995 -> 95 // 2000 -> 00