Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.11)

project(Lib-SWOC CXX)
set(LIBSWOC_VERSION "1.3.12")
set(LIBSWOC_VERSION "1.4.0")
set(CMAKE_CXX_STANDARD 17)
include(GNUInstallDirs)

Expand All @@ -22,6 +22,10 @@ set(HEADER_FILES
include/swoc/IntrusiveDList.h
include/swoc/IntrusiveHashMap.h
include/swoc/swoc_ip.h
include/swoc/IPEndpoint.h
include/swoc/IPAddr.h
include/swoc/IPSrv.h
include/swoc/IPRange.h
include/swoc/Lexicon.h
include/swoc/MemArena.h
include/swoc/MemSpan.h
Expand Down
53 changes: 33 additions & 20 deletions code/include/swoc/DiscreteRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -812,34 +812,27 @@ template <typename METRIC, typename PAYLOAD> class DiscreteSpace {
/** Find the payload at @a metric.
*
* @param metric The metric for which to search.
* @return The payload for @a metric if found, @c nullptr if not found.
* @return An iterator for the item or the @c end iterator if not.
*/
iterator find(METRIC const &metric);

/** Find the payload at @a metric.
*
* @param metric The metric for which to search.
* @return An iterator for the item or the @c end iterator if not.
*/
const_iterator find(METRIC const &metric) const;

/// @return The number of distinct ranges.
size_t count() const;

iterator
begin() {
return _list.begin();
}

iterator
end() {
return _list.end();
}
iterator begin() { return _list.begin(); }
iterator end() { return _list.end(); }
const_iterator begin() const { return _list.begin(); }
const_iterator end() const { return _list.end(); }

/// Remove all ranges.
void
clear() {
for (auto &node : _list) {
std::destroy_at(&node.payload());
}
_list.clear();
_root = nullptr;
_arena.clear();
_fa.clear();
}
void clear();

protected:
/** Find the lower bound range for @a target.
Expand Down Expand Up @@ -962,6 +955,13 @@ DiscreteSpace<METRIC, PAYLOAD>::find(METRIC const &metric) -> iterator {
return this->end();
}

template <typename METRIC, typename PAYLOAD>
auto
DiscreteSpace<METRIC, PAYLOAD>::find(METRIC const &metric) const -> const_iterator
{
return const_cast<self_type *>(this)->find(metric);
}

template <typename METRIC, typename PAYLOAD>
auto
DiscreteSpace<METRIC, PAYLOAD>::lower_bound(METRIC const &target) -> Node * {
Expand Down Expand Up @@ -1519,4 +1519,17 @@ DiscreteSpace<METRIC, PAYLOAD>::blend(DiscreteSpace::range_type const &range, U
return *this;
}

template <typename METRIC, typename PAYLOAD>
void
DiscreteSpace<METRIC, PAYLOAD>::clear()
{
for (auto &node : _list) {
std::destroy_at(&node.payload());
}
_list.clear();
_root = nullptr;
_arena.clear();
_fa.clear();
}

}} // namespace swoc::SWOC_VERSION_NS
Loading