#ifndef COMPACT_FLAT_MAP_INL_H_ #error "Direct inclusion of this file is not allowed, include compact_flat_map.h" // For the sake of sane code completion. #include "compact_flat_map.h" #endif namespace NYT { /////////////////////////////////////////////////////////////////////////////// template template TCompactFlatMap::TCompactFlatMap(TInputIterator begin, TInputIterator end) { insert(begin, end); } template TCompactFlatMap::TCompactFlatMap(std::initializer_list values) : TCompactFlatMap(values.begin(), values.end()) { } template bool TCompactFlatMap::operator==(const TCompactFlatMap& rhs) const { return Storage_ == rhs.Storage_; } template bool TCompactFlatMap::operator!=(const TCompactFlatMap& rhs) const { return !(*this == rhs); } template typename TCompactFlatMap::iterator TCompactFlatMap::begin() { return Storage_.begin(); } template typename TCompactFlatMap::const_iterator TCompactFlatMap::begin() const { return Storage_.begin(); } template typename TCompactFlatMap::const_iterator TCompactFlatMap::cbegin() const { return Storage_.begin(); } template typename TCompactFlatMap::iterator TCompactFlatMap::end() { return Storage_.end(); } template typename TCompactFlatMap::const_iterator TCompactFlatMap::end() const { return Storage_.end(); } template typename TCompactFlatMap::const_iterator TCompactFlatMap::cend() const { return Storage_.end(); } template void TCompactFlatMap::reserve(size_type n) { Storage_.reserve(n); } template typename TCompactFlatMap::size_type TCompactFlatMap::size() const { return Storage_.size(); } template int TCompactFlatMap::ssize() const { return static_cast(Storage_.size()); } template bool TCompactFlatMap::empty() const { return Storage_.empty(); } template void TCompactFlatMap::clear() { Storage_.clear(); } template void TCompactFlatMap::shrink_to_small() { Storage_.shrink_to_small(); } template typename TCompactFlatMap::iterator TCompactFlatMap::find(const K& k) { auto [rangeBegin, rangeEnd] = equal_range(k); return rangeBegin == rangeEnd ? end() : rangeBegin; } template typename TCompactFlatMap::const_iterator TCompactFlatMap::find(const K& k) const { auto [rangeBegin, rangeEnd] = equal_range(k); return rangeBegin == rangeEnd ? end() : rangeBegin; } template bool TCompactFlatMap::contains(const K& k) const { return find(k) != end(); } template auto TCompactFlatMap::insert(const value_type& value) -> std::pair { return do_insert(value); } template auto TCompactFlatMap::insert(value_type&& value) -> std::pair { return do_insert(std::move(value)); } template template auto TCompactFlatMap::do_insert(TArg&& value) -> std::pair { auto [rangeBegin, rangeEnd] = equal_range(value.first); if (rangeBegin != rangeEnd) { return {rangeBegin, false}; } else { auto it = Storage_.insert(rangeBegin, std::forward(value)); return {it, true}; } } template template void TCompactFlatMap::insert(TInputIterator begin, TInputIterator end) { for (auto it = begin; it != end; ++it) { insert(*it); } } template template auto TCompactFlatMap::emplace(TArgs&&... args) -> std::pair { return insert(value_type(std::forward(args)...)); } template V& TCompactFlatMap::operator[](const K& k) { auto [it, inserted] = insert({k, V()}); return it->second; } template void TCompactFlatMap::erase(const K& k) { auto [rangeBegin, rangeEnd] = equal_range(k); erase(rangeBegin, rangeEnd); } template void TCompactFlatMap::erase(iterator pos) { Storage_.erase(pos); // Try to keep the storage inline. This is why erase doesn't return an iterator. Storage_.shrink_to_small(); } template void TCompactFlatMap::erase(iterator b, iterator e) { Storage_.erase(b, e); // Try to keep the storage inline. This is why erase doesn't return an iterator. Storage_.shrink_to_small(); } template std::pair::iterator, typename TCompactFlatMap::iterator> TCompactFlatMap::equal_range(const K& k) { auto result = std::equal_range(Storage_.begin(), Storage_.end(), k, TKeyComparer()); YT_ASSERT(std::distance(result.first, result.second) <= 1); return result; } template std::pair::const_iterator, typename TCompactFlatMap::const_iterator> TCompactFlatMap::equal_range(const K& k) const { auto result = std::equal_range(Storage_.begin(), Storage_.end(), k, TKeyComparer()); YT_ASSERT(std::distance(result.first, result.second) <= 1); return result; } template typename TCompactFlatMap::const_iterator TCompactFlatMap::lower_bound(const K& k) const { return std::lower_bound(Storage_.begin(), Storage_.end(), k, TKeyComparer()); } template typename TCompactFlatMap::iterator TCompactFlatMap::lower_bound(const K& k) { return std::lower_bound(Storage_.begin(), Storage_.end(), k, TKeyComparer()); } template typename TCompactFlatMap::const_iterator TCompactFlatMap::upper_bound(const K& k) const { return std::upper_bound(Storage_.begin(), Storage_.end(), k, TKeyComparer()); } template typename TCompactFlatMap::iterator TCompactFlatMap::upper_bound(const K& k) { return std::upper_bound(Storage_.begin(), Storage_.end(), k, TKeyComparer()); } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT