Posts tagged STL

Hash tables

:: STL, hashtable, unordered_map

Before C++11, hash tables could be used in C++ only with some tricks. The only associative container available in the STL used to be the std::map (along with its sibling, the multimap). This class, however, is implemented as a binary search tree, and does not provide a way to customize a hash function. What hurt me most was that you didn’t have the great performances offered by a true hash map: almost constant time insert, delete, and search (depending on how good is the hash function). You insert in O(log N) time. You find in O(log N) time. Too bad.

STL Algorithms, part 4

:: algorithms, C++, STL, adjacent_find, count, count_if, find, find_end, find_first

We have seen some examples of usage of the find algorithm, with its variants find_if and find_if_not. In this installment, we are going to see other variants of finding algorithms, plus another algorithm useful when counting items in a sequence, count. Remember that we are still in the realm of non-modifying sequence algorithms (but see the discussion about for_each here).

STL Algorithms, part 3

:: algorithms, C++, STL

In the previous posts of this series, we have had a glance at non-modifying sequence algorithms, i.e., the algorithms that are supposed not to modify the elements of a sequence (or at least, the structure of the sequence; see the observations about for_each.

In this installment, as anticipated, we will start looking at the algorithms for searching.

STL Algorithms, part 2

:: algorithms, C++, STL

Previously on C++ Orienteering

In the previous installment, we have introduced three algorithms, all_of, any_of, and none_of, very useful to determine whether a range of elements satisfy some predicate, expressed as a lambda.

In this second episode, we will explore more algorithms offered by the STL. My objective, in the long run, is to cover all of them with examples, and maybe grasp the ideas that might come to my mind during the process. As usual, if you have any doubt or just spot a plain error, I’d greatly appreciate if you let me know.

STL Algorithms, part 1

:: algorithms, all_of, any_of, C++, none_of, STL

Why algorithms

Standard algorithms have a prominent value in the C++ standard template library (STL). They present the great advantage of expressing an operation applied on a range of elements in a container. In this series, I am going to review all the algorithms introduced in the C++11 standard, presenting it in digestible chunks, and will provide at least an example of application for each one.