Git Product home page Git Product logo

sorted_flat_deque's Introduction

sorted_flat_deque

C++11, STL-like API, bidirectional iterator, one memory allocation in the circular buffer.

push - O(n/2)
pop - O(1)
min - O(1)
median - O(1)
max - O(1)

Applicability:

The container is well suited in cases where you need to constantly receive min, max, median elements with the constantly insertion of new data (points).

Benchmark result:

MSVC142x64, Kaby Lake, 3.88 GHz
benchmark result

Principle of usage:

  1. Container initialization
sorted_flat_deque<int32_t> deque;
                       ╔═══╤═══╤═══╤═══╗
deque.set_max_size(4); ║   │   │   │   ║  // internal circular buffer
                       ╚═══╧═══╧═══╧═══╝
  1. Pushing items
                    ╔═══╤═══╤═══╤═══╗
deque.push_back(7); ║ 7 │   │   │   ║
                    ╚═══╧═══╧═══╧═══╝
                    ╔═══╤═══╤═══╤═══╗
deque.push_back(2); ║ 7f│ 2b│   │   ║ // b - back position, f - front position
                    ╚═══╧═══╧═══╧═══╝
                    ╔═══╤═══╤═══╤═══╗
deque.push_back(6); ║ 7f2 │ 6b│   ║
                    ╚═══╧═══╧═══╧═══╝
                    ╔═══╤═══╤═══╤═══╗
deque.push_back(1); ║ 7f26 │ 1b║
                    ╚═══╧═══╧═══╧═══╝
                    ╔═══╤═══╤═══╤═══╗
deque.push_back(3); ║ 3b│ 2f61// element '7' was automatically removed from front
                    ╚═══╧═══╧═══╧═══╝
  1. Accessing to min, max or median elements
for (auto it = deque.cbegin(); it != deque.cend(); ++it) {
    std::cout << *it << " ";
}
std::cout << std::endl; // 1 2 3 6
deque.min();    // 1
deque.median(); // 2
deque.max();    // 6

sorted_flat_deque's People

Contributors

yurablok avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

sorted_flat_deque's Issues

small bug in constructor

m_comparator assigment is missing

sorted_flat_deque<item_t>& operator=(const sorted_flat_deque<item_t>& other) {
m_size = other.m_size;
m_minOffset = other.m_minOffset;
m_medianOffset = other.m_medianOffset;
m_medianPos = other.m_medianPos;
m_maxOffset = other.m_maxOffset;
m_nodes = other.m_nodes;
return *this;
}
sorted_flat_deque<item_t>& operator=(sorted_flat_deque<item_t>&& other) {
m_size = other.m_size; other.m_size = 0;
m_minOffset = other.m_minOffset; other.m_minOffset = position_max;
m_medianOffset = other.m_medianOffset; m_medianOffset = position_max;
m_medianPos = other.m_medianPos; m_medianPos = position_max;
m_maxOffset = other.m_maxOffset; m_maxOffset = position_max;
m_nodes = std::move(other.m_nodes);
return *this;
}

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.