# Poco

# template < class Value, class HashFunc = Hash < Value >>

# class HashSet

Library: Foundation
Package: Hashing
Header: Poco/HashSet.h

## Description

This class implements a set using a LinearHashTable.

A HashSet can be used just like a std::set.

## Member Summary

Member Functions: begin, clear, count, empty, end, erase, find, insert, operator =, size, swap

## Types Aliases

### ConstIterator

using ConstIterator = typename HashTable::ConstIterator;

### ConstPointer

using ConstPointer = const Value *;

### ConstReference

using ConstReference = const Value &;

### Hash

using Hash = HashFunc;

### HashTable

using HashTable = LinearHashTable < ValueType, Hash >;

### Iterator

using Iterator = typename HashTable::Iterator;

### Pointer

using Pointer = Value *;

### Reference

using Reference = Value &;

### ValueType

using ValueType = Value;

## Constructors

### HashSet

HashSet() = default;

Creates an empty HashSet.

### HashSet

HashSet(
std::size_t initialReserve
);

Creates the HashSet, using the given initialReserve.

### HashSet

HashSet(
const HashSet & set
);

Creates the HashSet by copying another one.

## Destructor

### ~HashSet

~HashSet() = default;

Destroys the HashSet.

## Member Functions

### begin

ConstIterator begin() const;

Returns an iterator pointing to the first entry, if one exists.

### begin

Iterator begin();

Returns an iterator pointing to the first entry, if one exists.

### clear

void clear();

Erases all elements.

### count

std::size_t count(
const ValueType & value
) const;

Returns the number of elements with the given value, with is either 1 or 0.

### empty

bool empty() const;

Returns true iff the table is empty.

### end

ConstIterator end() const;

Returns an iterator pointing to the end of the table.

### end

Iterator end();

Returns an iterator pointing to the end of the table.

### erase

void erase(
Iterator it
);

Erases the element pointed to by it.

### erase

void erase(
const ValueType & value
);

Erases the element with the given value, if it exists.

### find

ConstIterator find(
const ValueType & value
) const;

Finds an entry in the table.

### find

Iterator find(
const ValueType & value
);

Finds an entry in the table.

### insert

std::pair < Iterator, bool > insert(
const ValueType & value
);

Inserts an element into the set.

If the element already exists in the set, a pair(iterator, false) with iterator pointing to the existing element is returned. Otherwise, the element is inserted an a pair(iterator, true) with iterator pointing to the new element is returned.

### operator =

HashSet & operator = (
const HashSet & table
);

Assigns another HashSet.

### size

std::size_t size() const;

Returns the number of elements in the table.

### swap

void swap(
HashSet & set
) noexcept;

Swaps the HashSet with another one.