Code Monkey home page Code Monkey logo

qsparsehash's Introduction

QSparseHash

A small Qt wrapper for Google sparse_hash_map (and dense_hash_map also).

Installation

The wrapper itself is a single C++ header file (qsparsehash.h). Just include it to your project.

Compatibility

QSparseHash is tested with Qt 4.8 and sparsehash 1.10/2.0.2. It may work with older versions, but I've not tested it.

How to use

QSparseHash class derives sparse_hash_map (QDenseHash derives dense_hash_map), so it's 100% API compatible with original Google implementation. But it also has some methods to be partially compatible with QHash (to be used as a drop-in QHash replacement). Also keep in mind that QSparseHash has QHash-incompatible iterators, there's a bit different syntax (see example below).

Examples

Creating, inserting and removing values:

QSparseHash<QString, int> hash;
hash.insert("foo", 1);
hash.insert("bar", 2);
hash["baz"] = 3;
// accessing values
printf("baz: %d\n", hash["baz"]);
// removing
hash.set_deleted_key(""); // if you remove items from hash, you must set deleted_key
hash.remove("foo");
printf("count: %d\n", hash.count());

Iterating over hash:

QSparseHash<QString, int> hash;
hash.insert("foo", 1);
hash.insert("bar", 2);
QSparseHash<QString, int>::const_iterator i = hash.begin();
while (i != hash.end()) {
    printf("%s: %d\n", qPrintable(i->first), i->second); // iterator points to std::pair<Key,Value>
    i++;
}

Does hash contain a key?

QSparseHash<QString, int> hash;
hash.insert("foo", 1);
hash.insert("bar", 2);
if (hash.contains("baz"))
    printf("hash contains baz\n");
if (hash.contains("foo"))
    printf("hash contains foo\n);

Dense hash example:

QDenseHash<QString, int> hash; 
hash.set_empty_key(""); // going to use "" as empty_key
hash.set_deleted_key("!"); // empty_key must not match deleted_key
hash.insert("foo", 1);
hash.insert("bar", 2);
hash.remove("bar");
printf("foo: %d\n", hash["foo"]);

More documentation

You may also be interested in these external docs:

githalytics.com alpha

qsparsehash's People

Contributors

romangrebennikov avatar shuttie avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.