Last active
August 29, 2015 14:02
-
-
Save psycharo-zz/f423aeaf71c0b1dcf4d3 to your computer and use it in GitHub Desktop.
simple c++11ish heap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| map<double, size_t> top; | |
| size_t max_size = 100; | |
| auto top_add = [&top,max_size](double value, size_t id) | |
| { | |
| if (top.size() < max_size) | |
| top.insert(make_pair(value, id)); | |
| else | |
| { | |
| if (top.begin()->first < value) | |
| { | |
| top.erase(top.begin()); | |
| top.insert(make_pair(value,id)); | |
| } | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment