Go

draft need to be improved Slice GOtype slice struct { array unsafe.Pointer len int cap int } // 扩容 func nextslicecap(newLen, oldCap int) int { newcap := oldCap doublecap := newcap + newcap if newLen > doublecap { return newLen } const threshold = 256 if oldCap < threshold { return doublecap } for { // 1.25x newcap += (newcap + 3*threshold) >> 2 if uint(newcap) >= uint(newLen) { break } } // overflowed if newcap <= 0 { return newLen } return newcap } Map GOtype Map struct { used uint64 // The number of filled slots seed uintptr // the hash seed, computed as a unique random number per map. // The directory of tables. // Normally dirPtr points to an array of table pointers // dirPtr *[dirLen]*table dirPtr unsafe.Pointer dirLen int // 1 << globalDepth globalDepth uint8 // The number of bits to use in table directory lookups. globalShift uint8 // The number of bits to shift out, 64 - globalDepth writing uint8 // detect the race. tombstonePossible bool // whether a table in this map contains a tombstone. clearSeq uint64 // version number, used to detect map clears during iteration. } Swiss Table refer: Faster Go maps with Swiss Tables ...

March 2, 2026

Redis Datastructure

Redis 数据结构 逻辑类型 (Type) 底层数据结构 (Internal Encoding) String int, embstr, raw (SDS) List quicklist Hash listpack, hashtable Set intset, hashtable ZSet listpack, skiplist + hashtable graph TD A[redisObject] --> B{type} B -->|STRING| C[int / embstr / raw] B -->|LIST| D[quicklist] B -->|HASH| E{size?} B -->|SET| F{all int?} B -->|ZSET| G{size?} E -->|小| H[listpack] E -->|大| I[hashtable] F -->|yes & 少| J[intset] F -->|no| K[hashtable] G -->|小| L[listpack] G -->|大| M[skiplist + hashtable]每种类型根据数据量自动切换编码:小数据用紧凑结构省内存,大数据切高效结构保性能。 ...

February 12, 2026