Code Monkey home page Code Monkey logo

qt-ordered-map's Introduction

Qt Ordered Map

Github Issues Build Status Average time to resolve an issue

A Qt based implementation of an ordered map.

An ordered map stores key-value pairs according to the insertion order of the keys. It supports a sub-set of the QMap API, as certain APIs like QMap::insertMulti() etc do not make sense for an ordered map.

OrderedMap stores keys according to their insertion order, so if you add a key that already exists, it's order is changed to being the last key in the map. Eg:

#include "orderedmap.h"
...
OrderedMap<int, int> om;
om.insert(1,1);
om.insert(2,2);
// Order of keys is [1, 2]

om.insert(1,1);
// Order of keys is [2, 1]

Here, another example that shows a map of QString > int:

OrderedMap<QString, int> map;

// put some values
map["z-key"] = 10;
map["a-key"] = 20;
map["c-key"] = 15;

// edit some values
map["a-key"] = 21;

foreach (int value, map.values()) {
    qDebug() << value;
}

// [Output will be]:
// > 10
// > 21
// > 15

foreach (QString key, map.keys()) {
    qDebug() << key << ">" << map[key];
}

// [Output will be]:
// > "z-key" > 10
// > "a-key" > 21
// > "c-key" > 15

Requirements

  • The key type for the OrderedMap must provide operator==() and a global hash function called qHash().

Limitations

  • OrderedMap currently does NOT support implicit sharing like other Qt containers. A deep-copy will be made whenever copying the container with either copy constructor or assignment operator.

Performance

OrderedMap uses a hashtable (QHash) for storing the data and a map (QLinkedList) for storing the order of the keys.

Key Lookup Insertion Removal
Average Worst Case Average Worst Case Average Worst Case
OrderedMap Amortized O(1) O(n) Amortized O(1) O(n) Amortized O(1) O(n)

qt-ordered-map's People

Contributors

gitantonio avatar mandeepsandhu avatar slysven avatar vadi2 avatar

Watchers

 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.