hashtable_pool.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package s2
  2. import "sync"
  3. // Table size constants
  4. const (
  5. betterLongTableBits = 17
  6. betterLongTableSize = 1 << betterLongTableBits // 131072
  7. betterShortTableBits = 14
  8. betterShortTableSize = 1 << betterShortTableBits // 16384
  9. betterSnappyLongTableBits = 16
  10. betterSnappyLongTableSize = 1 << betterSnappyLongTableBits // 65536
  11. bestLongTableBits = 19
  12. bestLongTableSize = 1 << bestLongTableBits // 524288
  13. bestShortTableBits = 16
  14. bestShortTableSize = 1 << bestShortTableBits // 65536
  15. )
  16. type betterTables struct {
  17. lTable [betterLongTableSize]uint32
  18. sTable [betterShortTableSize]uint32
  19. }
  20. var betterTablePool = sync.Pool{New: func() interface{} { return &betterTables{} }}
  21. // betterSnappyTables holds better-snappy compression hash tables.
  22. type betterSnappyTables struct {
  23. lTable [betterSnappyLongTableSize]uint32
  24. sTable [betterShortTableSize]uint32
  25. }
  26. var betterSnappyTablePool = sync.Pool{New: func() interface{} { return &betterSnappyTables{} }}
  27. // bestTables holds best compression hash tables.
  28. type bestTables struct {
  29. lTable [bestLongTableSize]uint64
  30. sTable [bestShortTableSize]uint64
  31. }
  32. var bestTablePool = sync.Pool{New: func() interface{} { return &bestTables{} }}
  33. // getBetterTables gets a zeroed betterTables from the pool.
  34. func getBetterTables() *betterTables {
  35. t := betterTablePool.Get().(*betterTables)
  36. *t = betterTables{}
  37. return t
  38. }
  39. // getBetterSnappyTables gets a zeroed betterSnappyTables from the pool.
  40. func getBetterSnappyTables() *betterSnappyTables {
  41. t := betterSnappyTablePool.Get().(*betterSnappyTables)
  42. *t = betterSnappyTables{}
  43. return t
  44. }
  45. // getBestTables gets a zeroed bestTables from the pool.
  46. func getBestTables() *bestTables {
  47. t := bestTablePool.Get().(*bestTables)
  48. *t = bestTables{}
  49. return t
  50. }