Azrar - a String interning library for C++ with faster comparisons and reduced memory footprint"
Comments and critics are welcome :-)
Github link: [https://github.com/kboutora/Azrar](https://github.com/kboutora/Azrar)
This is a lightweight C++ (14 and +) library for string interning and indexing that can significantly improve performance in applications dealing with repeated string comparisons or using strings as maps key.
The library is header only.
**How it works:**
Instead of working with strings, Azrar maintains a dictionary where each unique string gets assigned a unique index..
Working with these unique indexes makes copying, comparing, and hashing operations substantially faster.
Github link: [https://github.com/kboutora/Azrar](https://github.com/kboutora/Azrar)
**Usage minimalist example:**
include "Azrar.h"
include <map>
include <iostream>
using IdxString = Azrar::StringIndex<uint32_t>;
int main(int , char **)
{
// Expect to print 4 (sizeof (uint32_t))
std::cout << "sizeof(IdxString): " << sizeof(IdxString) << " bytes\n\n";
IdxString city1("seattle");
IdxString city2("seattle");
IdxString city3("portland");
// Fast O(1) comparison (compares integers, not string contents)
if (city1 == city2) {
std::cout << "Same city!\n";
}
// Use as map keys - much faster lookups than std::string
std::map<IdxString, int> population;
population[city1] = 750000;
population[city3] = 650000;
// Access the original string when needed
std::cout << "City: " << city1.c_str() << "\n";
return 0;
}
https://redd.it/1rophrb
@r_cpp
Post #24829
14