STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
examples/containers/map1.cpp

This example code is explained in the STXXL Map (B+-tree) section

/***************************************************************************
* examples/containers/map1.cpp
*
* Part of the STXXL. See http://stxxl.sourceforge.net
*
* Copyright (C) 2013 Daniel Feist <[email protected]>
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
**************************************************************************/
//! [example]
#include <stxxl/map>
#include <iostream>
#define DATA_NODE_BLOCK_SIZE (4096)
#define DATA_LEAF_BLOCK_SIZE (4096)
//! [comparator]
struct CompareGreater
{
bool operator () (const int& a, const int& b) const
{ return a > b; }
static int max_value()
};
//! [comparator]
int main()
{
// template parameter <KeyType, DataType, CompareType, RawNodeSize, RawLeafSize, PDAllocStrategy (optional)>
// Constructor map(node_cache_size_in_bytes, leaf_cache_size_in_bytes)
map_type my_map((map_type::node_block_type::raw_size)*3, (map_type::leaf_block_type::raw_size)*3);
my_map.insert(std::pair<int, char>(1, 'a'));
my_map.insert(std::pair<int, char>(2, 'b'));
my_map.insert(std::pair<int, char>(3, 'c'));
my_map.insert(std::pair<int, char>(4, 'd'));
my_map.erase(3);
map_type::iterator iter;
std::cout << "my_map contains:\n";
for (iter = my_map.begin(); iter != my_map.end(); ++iter)
{
std::cout << iter->first << " => " << iter->second << std::endl;
}
map_type::iterator iter_low, iter_up;
iter_low = my_map.lower_bound(1); // iter_low points to (1,a) in this case
iter_up = my_map.upper_bound(3); // iter_up points to (2,b) in this case
std::cout << "lower bound " << iter_low->second << ", upper bound " << iter_up->second << std::endl;
return 0;
}
//! [example]