Skip to content
Philipp Gschwandtner edited this page Jun 6, 2017 · 2 revisions

allscale::utils::Bag

Defined in header "allscale/utils/bag.h"

template<typename T>
class Bag;

The Bag container represents an unordered set of elements, potentially including duplicates.

Member functions

Member function Description
bool empty() const Tests whether this Bag is empty
std::size_t size() const Returns the size of this Bag
void insert(const T& element) Inserts an element into this Bag
void remove(const T& element) Removes an element from this Bag
bool contains(const T& element) Tests whether a given element is contained in this Bag
auto begin() const Obtains an iterator pointing to the beginning of this Bag
auto end() const Obtains an iterator pointing to the end of this Bag
template<typename Body>
void updateFilter(const Body& body)
Updates all elements with the given update function and removes elements for which the update function returns false
template<typename Predicate>
void filter(const Predicate& pred)
Removes all elements for which the given predicate function returns false

Examples

#include <allscale/utils/bag.h>

using allscale::utils;

// create a Bag of integers
Bag<int> bag;

// add and remove a few elements
bag.insert(10);
bag.insert(10);
bag.insert(10);
bag.remove(10);
bag.insert(11);
bag.insert(11);
bag.insert(12);

// increase all elements by one and only keep the ones smaller than 12 after the increase
b.updateFilter([](int& i) { 
  i++; 
  return i < 12;
});
Clone this wiki locally