Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8139577
  • 博文数量: 594
  • 博客积分: 13065
  • 博客等级: 上将
  • 技术积分: 10324
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-26 16:44
个人简介

推荐: blog.csdn.net/aquester https://github.com/eyjian https://www.cnblogs.com/aquester http://blog.chinaunix.net/uid/20682147.html

文章分类

全部博文(594)

分类: LINUX

2008-12-11 14:31:00

可以较容易的用来替换准标准的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 . Our new homepage is located at .

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 .

For downloads, news, and other information, visit our

Example

This is by no means a complete example; it simply gives you a feel for what the Sparsehash API looks like. 
  1. #include <iostream>
  2. #include <google/sparse_hash_map>

  3. struct eqstr
  4. {
  5.     bool operator()(const char* s1, const char* s2) const
  6.     {
  7.         return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
  8.     }
  9. };

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

  13.     months.set_deleted_key(NULL);
  14.     months["january"] = 31;
  15.     months["february"] = 28;
  16.     months["march"] = 31;
  17.     months["april"] = 30;
  18.     months["may"] = 31;
  19.     months["june"] = 30;
  20.     months["july"] = 31;
  21.     months["august"] = 31;
  22.     months["september"] = 30;
  23.     months["october"] = 31;
  24.     months["november"] = 30;
  25.     months["december"] = 31;

  26.     std::cout << "september -> " << months["september"] << std::endl;
  27.     std::cout << "april -> " << months["april"] << std::endl;
  28.     std::cout << "june -> " << months["june"] << std::endl;
  29.     std::cout << "november -> " << months["november"] << std::endl;
  30.     
  31.     return 0;
  32. }

阅读(2646) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~