ART index in ShannonBase

ยท Medium ยท

2 min read Original article โ†—

Shannon Data AI

#ShannonBase, Hi all, A new ART implementation has the below:
๐Ÿ”’ **Concurrency Support**
- Uses `std::shared_mutex` for reader-writer locks
- Tree-level locking with `tree_mutex` for structural modifications
- Node-level locking for fine-grained concurrency control
- Atomic operations for size tracking (`size.fetch_add/fetch_sub`)

๐Ÿ“ฆ **Multi-value Support**
- Each leaf node (`Art_leaf`) contains a vector of values
- Supports storing multiple values per key (similar to multi-map)
- `vcount` atomic counter tracks value count

๐Ÿ’พ **Memory Management**
- Uses smart pointers (`ArtNodePtr`) for automatic memory management
- Factory pattern with `make_art_node<>` template function for node creation
- Proper cleanup in delete operations

๐Ÿ”„ **Node Type System**
- Implements all four ART node types: NODE4, NODE16, NODE48, NODE256
- Automatic node type upgrading/downgrading based on child count
- Efficient memory usage through progressive node expansion

๐Ÿ“ **Prefix Compression**
- Implements prefix compression to reduce memory usage
- `MAX_PREFIX_LEN` limits prefix storage overhead
- Automatic prefix splitting during insertion

โš™๏ธ **Implementation Details**
- Template-based design for type safety and code reuse
- Recursive algorithms for insert/delete operations with proper locking
- Comprehensive error handling with null checks and assertions
- Iterator support with callback functions for traversal
- Range query support through prefix iteration

๐Ÿš€ **Performance Considerations**
- Fine-grained locking enables better concurrency than global locks
- Path copying during modification to maintain consistency
- Automatic structural adaptation maintains optimal performance characteristics
- Cache-friendly node layouts for better memory locality

๐ŸŽฏ **Summary**
This implementation balances concurrency, memory efficiency, and performance while maintaining the core ART tree properties. The multi-value support makes it particularly suitable for database index or key-value store applications where multiple entries might share the same key.
You can **star** it for us works at: https://github.com/Shannon-Data/ShannonBase