doc.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2014 The b Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package b implements the B+tree flavor of a BTree.
  5. //
  6. // Changelog
  7. //
  8. // 2016-07-16: Update benchmark results to newer Go version. Add a note on
  9. // concurrency.
  10. //
  11. // 2014-06-26: Lower GC presure by recycling things.
  12. //
  13. // 2014-04-18: Added new method Put.
  14. //
  15. // Concurrency considerations
  16. //
  17. // Tree.{Clear,Delete,Put,Set} mutate the tree. One can use eg. a
  18. // sync.Mutex.Lock/Unlock (or sync.RWMutex.Lock/Unlock) to wrap those calls if
  19. // they are to be invoked concurrently.
  20. //
  21. // Tree.{First,Get,Last,Len,Seek,SeekFirst,SekLast} read but do not mutate the
  22. // tree. One can use eg. a sync.RWMutex.RLock/RUnlock to wrap those calls if
  23. // they are to be invoked concurrently with any of the tree mutating methods.
  24. //
  25. // Enumerator.{Next,Prev} mutate the enumerator and read but not mutate the
  26. // tree. One can use eg. a sync.RWMutex.RLock/RUnlock to wrap those calls if
  27. // they are to be invoked concurrently with any of the tree mutating methods. A
  28. // separate mutex for the enumerator, or the whole tree in a simplified
  29. // variant, is necessary if the enumerator's Next/Prev methods per se are to
  30. // be invoked concurrently.
  31. //
  32. // Generic types
  33. //
  34. // Keys and their associated values are interface{} typed, similar to all of
  35. // the containers in the standard library.
  36. //
  37. // Semiautomatic production of a type specific variant of this package is
  38. // supported via
  39. //
  40. // $ make generic
  41. //
  42. // This command will write to stdout a version of the btree.go file where every
  43. // key type occurrence is replaced by the word 'KEY' and every value type
  44. // occurrence is replaced by the word 'VALUE'. Then you have to replace these
  45. // tokens with your desired type(s), using any technique you're comfortable
  46. // with.
  47. //
  48. // This is how, for example, 'example/int.go' was created:
  49. //
  50. // $ mkdir example
  51. // $ make generic | sed -e 's/KEY/int/g' -e 's/VALUE/int/g' > example/int.go
  52. //
  53. // No other changes to int.go are necessary, it compiles just fine.
  54. //
  55. // Running the benchmarks for 1000 keys on a machine with Intel i5-4670 CPU @
  56. // 3.4GHz, Go 1.7rc1.
  57. //
  58. // $ go test -bench 1e3 example/all_test.go example/int.go
  59. // BenchmarkSetSeq1e3-4 20000 78265 ns/op
  60. // BenchmarkGetSeq1e3-4 20000 67980 ns/op
  61. // BenchmarkSetRnd1e3-4 10000 172720 ns/op
  62. // BenchmarkGetRnd1e3-4 20000 89539 ns/op
  63. // BenchmarkDelSeq1e3-4 20000 87863 ns/op
  64. // BenchmarkDelRnd1e3-4 10000 130891 ns/op
  65. // BenchmarkSeekSeq1e3-4 10000 100118 ns/op
  66. // BenchmarkSeekRnd1e3-4 10000 121684 ns/op
  67. // BenchmarkNext1e3-4 200000 6330 ns/op
  68. // BenchmarkPrev1e3-4 200000 9066 ns/op
  69. // PASS
  70. // ok command-line-arguments 42.531s
  71. // $
  72. package b