Debian Codegraph @

s2/hashtable_pool.go

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