岚天逸见

Google Sparse Hash

可以较容易的用来替换准标准的hash_map和hash_set。

文件: sparsehash-1.3.zip
大小: 1210KB
下载: 下载

An extremely memory-efficient hash_map implementation, with only 2 bits/entry overhead.

We've Moved!

Google SparseHash is now hosted at code.google.com. Our new homepage is located athttp://code.google.com/p/google-sparsehash.

Overview

The Google SparseHash project contains several hash-map implementations in use at Google, with different performance characteristics, including an implementation that optimizes for space and one that optimizes for speed.

SparseHash is a template library; there are no binaries to install.

SparseHash is distributed under the terms of the BSD License.

For downloads, news, and other information, visit our Project Page

Example

This is by no means a complete example; it simply gives you a feel for what the Sparsehash API looks like.

#include <iostream>
#include <google/sparse_hash_map>

struct eqstr
{
    bool operator()(const char* s1, const char* s2) const
    {
        return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
    }
};

int main()
{
    google::sparse_hash_map<const char*, int, hash<const char*>, eqstr> months;

    months.set_deleted_key(NULL);
    months["january"] = 31;
    months["february"] = 28;
    months["march"] = 31;
    months["april"] = 30;
    months["may"] = 31;
    months["june"] = 30;
    months["july"] = 31;
    months["august"] = 31;
    months["september"] = 30;
    months["october"] = 31;
    months["november"] = 30;
    months["december"] = 31;

    std::cout << "september -> " << months["september"] << std::endl;
    std::cout << "april     -> " << months["april"] << std::endl;
    std::cout << "june      -> " << months["june"] << std::endl;
    std::cout << "november  -> " << months["november"] << std::endl;
    
    return 0;
}


posted on   岚天逸见  阅读(663)  评论(0编辑  收藏  举报

编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义

导航

统计信息

点击右上角即可分享
微信分享提示