Bits & Caches
Bit-level data manipulation and hardware-aware caching exploit machine word parallelism and spatial/temporal locality. Bitsets pack boolean vectors into 64-bit long words with bitwise operations; LRU caches couple hash tables with doubly linked lists to achieve O(1) get, update, and eviction.
Key Invariants & Rules
- 64-bit word packing: bit index i resides in word i >> 6 at bit mask 1L << (i & 63).
- Population count computes total set bits across packed words using hardware Hamming weight instructions.
- LRU Cache invariant: head points to Most Recently Used (MRU) node; tail points to Least Recently Used (LRU).
- On get or put of an existing key, the accessed node is unlinked and spliced directly to the MRU head in O(1) time.
- When cache size exceeds capacity, the tail node (LRU) is removed from both the linked list and the lookup map.
Must-Know Algorithms
Ultra-compact boolean storage using machine words with bitwise parallel operations.
Combines O(1) hash lookup with O(1) recency splicing and deterministic eviction.
Learning Path (2 Lessons)
Self-Check & Concept Review
1. How does a 64-bit Bitset locate the word index for bit i in constant time?
2. What bitwise operation is used to determine if bit i is set in word W?
3. Why does an LRU Cache require a DOUBLY linked list instead of a singly linked list?
4. In an LRU Cache, which entry is evicted when capacity is exceeded during a put?
5. What is the time complexity of testing membership of an element in a Bitset of N bits?