A wrapper around an unordered_map of T keyed by Ipv6Prefix using Hash as the hash function. More...
#include <DwmIpv6PrefixMap.hh>
Public Types | |
| using | MapType = std::unordered_map<Ipv6Prefix,T,Hash> |
| The types of our encapsulated containers. | |
| using | LengthMapType = std::map<uint8_t,uint64_t> |
| using | MapPair = std::pair<MapType,LengthMapType> |
| Internally we keep our maps in a pair. | |
Public Member Functions | |
| Ipv6PrefixMap () | |
| Default constructor. | |
| void | Add (const Ipv6Prefix &pfx, const T &value) |
Adds the given value to the map at key pfx. | |
| void | Add (std::unique_lock< std::shared_mutex > &lck, const Ipv6Prefix &pfx, const T &value) |
Adds the given value to the map at key pfx. | |
| bool | Find (const Ipv6Prefix &pfx, T &value) const |
Find the entry with key pfx. | |
| bool | Find (std::shared_lock< std::shared_mutex > &lck, const Ipv6Prefix &pfx, T &value) const |
Find the entry with key pfx. | |
| bool | Find (std::unique_lock< std::shared_mutex > &lck, const Ipv6Prefix &pfx, T &value) const |
Find the entry with key pfx. | |
| bool | FindLongest (const Ipv6Address &addr, std::pair< Ipv6Prefix, T > &value) const |
Find the longest match for the given IPv6 address addr. | |
| bool | FindLongest (std::shared_lock< std::shared_mutex > &lck, const Ipv6Address &addr, std::pair< Ipv6Prefix, T > &value) const |
Find the longest match for the given IPv6 address addr. | |
| bool | FindLongest (std::unique_lock< std::shared_mutex > &lck, const Ipv6Address &addr, std::pair< Ipv6Prefix, T > &value) const |
Find the longest match for the given IPv6 address addr. | |
| bool | FindMatches (const Ipv6Address &addr, std::vector< std::pair< Ipv6Prefix, T > > &values) const |
Find all matches for the given IPv6 address addr. | |
| bool | FindMatches (std::shared_lock< std::shared_mutex > &lck, const Ipv6Address &addr, std::vector< std::pair< Ipv6Prefix, T > > &values) const |
Find all matches for the given IPv6 address addr. | |
| bool | FindMatches (std::unique_lock< std::shared_mutex > &lck, const Ipv6Address &addr, std::vector< std::pair< Ipv6Prefix, T > > &values) const |
Find all matches for the given IPv6 address addr. | |
| bool | Remove (const Ipv6Prefix &pfx) |
Removes the entry for the given prefix pfx. | |
| bool | Remove (std::unique_lock< std::shared_mutex > &lck, const Ipv6Prefix &pfx) |
Removes the entry for the given prefix pfx. | |
| void | Clear () |
| Clears the map. | |
| void | Clear (std::unique_lock< std::shared_mutex > &lck) |
| Clears the map. | |
| bool | Empty () const |
| Returns true if the map is empty. | |
| bool | Empty (std::shared_lock< std::shared_mutex > &lck) const |
| Returns true if the map is empty. | |
| bool | Empty (std::unique_lock< std::shared_mutex > &lck) const |
| Returns true if the map is empty. | |
| std::istream & | Read (std::istream &is) |
| Reads the Ipv6PrefixMap from an istream. Returns the istream. | |
| std::ostream & | Write (std::ostream &os) const |
| Writes the Ipv6PrefixMap to an ostream. Returns the ostream. | |
| size_t | Read (FILE *f) |
Reads the Ipv6PrefixMap from f. | |
| size_t | Write (FILE *f) const |
Writes the Ipv6PrefixMap to f. | |
| ssize_t | Read (int fd) |
Reads the Ipv6PrefixMap from file descriptor fd. | |
| ssize_t | Write (int fd) const |
Writes the Ipv6PrefixMap to file descriptor fd. | |
| int | Read (gzFile gzf) |
Reads the Ipv6PrefixMap from gzf. | |
| int | Write (gzFile gzf) const |
Writes the Ipv6PrefixMap to gzf. | |
| int | BZRead (BZFILE *bzf) |
Reads the Ipv6PrefixMap from bzf. | |
| int | BZWrite (BZFILE *bzf) const |
Writes the Ipv6PrefixMap to bzf. | |
| uint64_t | StreamedLength () const |
| Returns the number of bytes that would be written if the Ipv6PrefixMap was written to a FILE, file descriptor or ostream. | |
| bool | Read (boost::asio::ip::tcp::socket &s, boost::system::error_code &ec) |
Reads the Ipv6PrefixMap from s. | |
| bool | Read (boost::asio::local::stream_protocol::socket &s, boost::system::error_code &ec) |
Reads the Ipv6PrefixMap from s. | |
| bool | Read (boost::asio::generic::stream_protocol::socket &s, boost::system::error_code &ec) |
Reads the Ipv6PrefixMap from s. | |
| bool | Write (boost::asio::ip::tcp::socket &s, boost::system::error_code &ec) const |
Writes the Ipv6PrefixMap to s. | |
| bool | Write (boost::asio::local::stream_protocol::socket &s, boost::system::error_code &ec) const |
Writes the Ipv6PrefixMap to s. | |
| bool | Write (boost::asio::generic::stream_protocol::socket &s, boost::system::error_code &ec) const |
Writes the Ipv6PrefixMap to s. | |
| std::shared_lock< std::shared_mutex > | SharedLock () const |
| Returns a shared lock of the Ipv6PrefixMap, in the locked state. | |
| std::unique_lock< std::shared_mutex > | UniqueLock () |
| Returns a unique lock of the Ipv6PrefixMap, in the locked state. | |
A wrapper around an unordered_map of T keyed by Ipv6Prefix using Hash as the hash function.
This isn't the fastest IPv6 prefix container, but... it's fast enough for my uses, and is very little code to maintain since it leverages the C++ standard library facilities.
Members are threadsafe (using a mutex).
| using Dwm::Ipv6PrefixMap< T, Hash >::MapPair = std::pair<MapType,LengthMapType> |
Internally we keep our maps in a pair.
This simplifies the I/O functions.
|
inline |
Adds the given value to the map at key pfx.
If the entry already exists, it will be replaced.

|
inline |
Adds the given value to the map at key pfx.
If the entry already exists, it will be replaced. lck must be a lock created with UniqueLock() and must be locked.

|
inline |
Reads the Ipv6PrefixMap from bzf.
Returns the number of bytes read on success, -1 on failure. Be wary; the integer return is risky (could overflow) but it's what bzlib's BZ2_bzRead() returns and we trickled up the return type.

|
inline |
Writes the Ipv6PrefixMap to bzf.
Returns the number of bytes written on success, -1 on failure. Be wary; the integer return is risky (could overflow) but it's what bzlib's BZ2_bzWrite() returns and we trickled up the return type.

|
inline |
Clears the map.
lck must be a lock created with UniqueLock() and must be locked.
|
inline |
Returns true if the map is empty.
lck must be a lock created with SharedLock() and must be locked.
|
inline |
Returns true if the map is empty.
lck must be a lock created with UniqueLock() and must be locked.
|
inline |
Find the entry with key pfx.
If found, sets value to the value stored at pfx and returns true. If not found, returns false.

|
inline |
Find the entry with key pfx.
If found, sets value to the value stored at pfx and returns true. If not found, returns false. lck must be a lock created with SharedLock() and must be locked.
|
inline |
Find the entry with key pfx.
If found, sets value to the value stored at pfx and returns true. If not found, returns false. lck must be a lock created with UniqueLock() and must be locked.
|
inline |
Find the longest match for the given IPv6 address addr.
If a match is found, sets value.first to the matching prefix and value.second to the value stored at the matching prefix and returns true. If no match is found, returns false.

|
inline |
Find the longest match for the given IPv6 address addr.
If a match is found, sets value.first to the matching prefix and value.second to the value stored at the matching prefix and returns true. If no match is found, returns false. lck must be a lock created with SharedLock() and must be locked.
|
inline |
Find the longest match for the given IPv6 address addr.
If a match is found, sets value.first to the matching prefix and value.second to the value stored at the matching prefix and returns true. If no match is found, returns false. lck must be a lock created with UniqueLock() and must be locked.
|
inline |
Find all matches for the given IPv6 address addr.
If matches are found, they are placed in values, in most-specific (longest prefix length) to least-specific (shortest prefix length) order and true is returned. If no matches are found, returns false.

|
inline |
Find all matches for the given IPv6 address addr.
If matches are found, they are placed in values, in most-specific (longest prefix length) to least-specific (shortest prefix length) order and true is returned. If no matches are found, returns false. lck must be a lock created with SharedLock() and must be locked.
|
inline |
Find all matches for the given IPv6 address addr.
If matches are found, they are placed in values, in most-specific (longest prefix length) to least-specific (shortest prefix length) order and true is returned. If no matches are found, returns false. lck must be a lock created with UniqueLock() and must be locked.
|
inline |
Reads the Ipv6PrefixMap from s.
Returns true on success, false on failure.

|
inline |
Reads the Ipv6PrefixMap from s.
Returns true on success, false on failure.

|
inline |
Reads the Ipv6PrefixMap from s.
Returns true on success, false on failure.

|
inline |
Reads the Ipv6PrefixMap from f.
Returns 1 on success, 0 on failure.

|
inline |
Reads the Ipv6PrefixMap from gzf.
Returns the number of bytes read on success, -1 on failure. Be wary; the integer return is risky (could overflow) but it's what zlib's gzread() returns and we trickled up the return type.

|
inline |
Reads the Ipv6PrefixMap from file descriptor fd.
Returns the number of bytes read on success, -1 on failure.

|
inline |
Removes the entry for the given prefix pfx.
Returns true if an entry was removed, false if no entry was found for pfx.

|
inline |
Removes the entry for the given prefix pfx.
Returns true if an entry was removed, false if no entry was found for pfx. lck must be a lock created with UniqueLock() and must be locked.

|
inline |
Returns a shared lock of the Ipv6PrefixMap, in the locked state.
This should be used with care to avoid deadlock. It is intended for scenarios where the caller needs to perform many read-only operations in quick succession and performance is paramount, since it allows one to call the members which accept a shared lock and hence do not lock and unlock on each call. Note that the only read-only member with significant locking overhead is Find(). FindLongest()'s locking overhead is dwarfed by the cycles it needs for other activities.
|
inline |
Returns a unique lock of the Ipv6PrefixMap, in the locked state.
This (and the members that accept a unique lock as an argument) should be used with care to avoid deadlock. It is intended for scenarios where the caller needs to perform many operations in quick succession and performance is paramount, since it allows one to call the members which accept a unique lock and hence do not lock and unlock on each call. Note that the only read-only member with significant locking overhead is Find(); FindLongest()'s locking overhead is dwarfed by the cycles it needs for other activities. Add() is a little bit faster for repetitive operations using the pre-locked version (about 5%).
|
inline |
Writes the Ipv6PrefixMap to s.
Returns true on success, false on failure.

|
inline |
Writes the Ipv6PrefixMap to s.
Returns true on success, false on failure.

|
inline |
Writes the Ipv6PrefixMap to s.
Returns true on success, false on failure.

|
inline |
Writes the Ipv6PrefixMap to f.
Returns 1 on success, 0 on failure.

|
inline |
Writes the Ipv6PrefixMap to gzf.
Returns the number of bytes written on success, -1 on failure. Be wary; the integer return is risky (could overflow) but it's what zlib's gzread() returns and we trickled up the return type.

|
inline |
Writes the Ipv6PrefixMap to file descriptor fd.
Returns the number of bytes written on success, -1 on failure.
