diff options
| author | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
|---|---|---|
| committer | Lucas de Castro Borges <lucas@gnuabordo.com.br> | 2025-02-11 15:07:35 -0300 |
| commit | 4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch) | |
| tree | 1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/util/immutable/details | |
| parent | aa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff) | |
| parent | 8f0827553e09872941945a093b647a4211a9db7f (diff) | |
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0'
with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/util/immutable/details')
| -rw-r--r-- | src/mongo/util/immutable/details/map.h | 233 | ||||
| -rw-r--r-- | src/mongo/util/immutable/details/memory_policy.h | 63 | ||||
| -rw-r--r-- | src/mongo/util/immutable/details/set.h | 110 |
3 files changed, 0 insertions, 406 deletions
diff --git a/src/mongo/util/immutable/details/map.h b/src/mongo/util/immutable/details/map.h deleted file mode 100644 index a66db19b412..00000000000 --- a/src/mongo/util/immutable/details/map.h +++ /dev/null @@ -1,233 +0,0 @@ -/** - * Copyright (C) 2023-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include <algorithm> - -namespace mongo::immutable::details::map { - -template <typename map, typename SearchKey> -bool equal(const typename map::key_type& a, const SearchKey& b) { - return !typename map::comp{}(a, b) && !typename map::comp{}(b, a); -} - -template <typename map, typename SearchKey> -[[nodiscard]] typename map::iterator lower_bound(const typename map::storage_type& storage, - const SearchKey& key) { - return std::lower_bound(storage.begin(), - storage.end(), - key, - [](const typename map::value_type& a, const SearchKey& b) -> bool { - return typename map::comp{}(a.first, b); - }); -} - -template <typename map, typename SearchKey> -[[nodiscard]] typename map::iterator find(const typename map::storage_type& storage, - const SearchKey& key) { - auto it = lower_bound<map>(storage, key); - if (it != storage.end() && equal<map>(it->first, key)) { - return it; - } - - return storage.end(); -} - -template <typename map, typename S, typename K, typename V> -[[nodiscard]] typename map::storage_type insert(S&& storage, K&& key, V&& value) { - auto it = lower_bound<map>(storage, key); - if (it != storage.end() && equal<map>(it->first, key)) { - return std::forward<S>(storage); - } - if (it == storage.end()) { - return std::forward<S>(storage).push_back( - std::make_pair(std::forward<K>(key), std::forward<V>(value))); - } - return std::forward<S>(storage).insert( - it.index(), std::make_pair(std::forward<K>(key), std::forward<V>(value))); -} - -template <typename map, typename S, typename K, typename V> -[[nodiscard]] typename map::storage_type insert(S&& storage, - typename map::iterator it, - K&& key, - V&& value) { - if (it != storage.end() && equal<map>(it->first, key)) { - return std::forward<S>(storage); - } - - if (it == storage.end()) { - if (typename map::comp{}(storage[storage.size() - 1].first, key)) { - return std::forward<S>(storage).push_back( - std::make_pair(std::forward<K>(key), std::forward<V>(value))); - } - return insert<map>(std::forward<S>(storage), std::forward<K>(key), std::forward<V>(value)); - } - - if (typename map::comp{}(key, it->first) && - (it.index() == 0 || typename map::comp{}((it - 1)->first, key))) { - return std::forward<S>(storage).insert( - it.index(), std::make_pair(std::forward<K>(key), std::forward<V>(value))); - } - - return insert<map>(std::forward<S>(storage), std::forward<K>(key), std::forward<V>(value)); -} - -template <typename map, typename S, typename K, typename U> -[[nodiscard]] typename map::storage_type update(S&& storage, K&& key, U&& valueUpdate) { - auto it = lower_bound<map>(storage, key); - if (it == storage.end()) { - return std::forward<S>(storage).push_back( - std::make_pair(std::forward<K>(key), valueUpdate(typename map::default_value{}()))); - } - - if (equal<map>(it->first, key)) { - return std::forward<S>(storage).set( - it.index(), std::make_pair(std::forward<K>(key), valueUpdate(it->second))); - } - - return insert<map>(std::forward<S>(storage), - std::forward<K>(key), - valueUpdate(typename map::default_value{}())); -} - -template <typename map, typename S, typename K, typename U> -[[nodiscard]] typename map::storage_type update(S&& storage, - typename map::iterator it, - K&& key, - U&& valueUpdate) { - if (it == storage.end()) { - if (typename map::comp{}(storage[storage.size() - 1].first, key)) { - return std::forward<S>(storage).push_back( - std::make_pair(std::forward<K>(key), valueUpdate(typename map::default_value{}()))); - } - return update<map>( - std::forward<S>(storage), std::forward<K>(key), std::forward<U>(valueUpdate)); - } - - if (equal<map>(it->first, key)) { - return std::forward<S>(storage).set( - it.index(), std::make_pair(std::forward<K>(key), valueUpdate(it->second))); - } - - if (typename map::comp{}(key, it->first) && - (it.index() == 0 || typename map::comp{}((it - 1)->first, key))) { - return std::forward<S>(storage).insert( - it.index(), - std::make_pair(std::forward<K>(key), valueUpdate(typename map::default_value{}()))); - } - - return insert<map>(std::forward<S>(storage), - std::forward<K>(key), - valueUpdate(typename map::default_value{}())); -} - -template <typename map, typename S, typename K, typename U> -[[nodiscard]] typename map::storage_type update_if_exists(S&& storage, K&& key, U&& valueUpdate) { - auto it = find<map>(storage, key); - if (it == storage.end()) { - return std::forward<S>(storage); - } - return std::forward<S>(storage).set( - it.index(), std::make_pair(std::forward<K>(key), valueUpdate(it->second))); -} - -template <typename map, typename S, typename K, typename U> -[[nodiscard]] typename map::storage_type update_if_exists(S&& storage, - typename map::iterator it, - K&& key, - U&& valueUpdate) { - if (it == storage.end() || !equal<map>(it->first, key)) { - return update_if_exists<map>( - std::forward<S>(storage), std::forward<K>(key), std::forward<U>(valueUpdate)); - } - return std::forward<S>(storage).set( - it.index(), std::make_pair(std::forward<K>(key), valueUpdate(it->second))); -} - -template <typename map, typename S, typename K, typename V> -[[nodiscard]] typename map::storage_type set(S&& storage, K&& key, V&& value) { - auto it = lower_bound<map>(storage, key); - if (it == storage.end()) { - return std::forward<S>(storage).push_back( - std::make_pair(std::forward<K>(key), std::forward<V>(value))); - } else if (!equal<map>(it->first, key)) { - return std::forward<S>(storage).insert( - it.index(), std::make_pair(std::forward<K>(key), std::forward<V>(value))); - } - return std::forward<S>(storage).set( - it.index(), std::make_pair(std::forward<K>(key), std::forward<V>(value))); -} - -template <typename map, typename S, typename K, typename V> -[[nodiscard]] typename map::storage_type set(S&& storage, - typename map::iterator it, - K&& key, - V&& value) { - if (it == storage.end()) { - if (typename map::comp{}(storage[storage.size() - 1].first, key)) { - return std::forward<S>(storage).push_back( - std::make_pair(std::forward<K>(key), std::forward<V>(value))); - } - return set<map>(std::forward<S>(storage), std::forward<K>(key), std::forward<V>(value)); - } - - if (equal<map>(it->first, key)) { - return std::forward<S>(storage).set( - it.index(), std::make_pair(std::forward<K>(key), std::forward<V>(value))); - } - - if (typename map::comp{}(key, it->first) && - (it.index() == 0 || typename map::comp{}((it - 1)->first, key))) { - return std::forward<S>(storage).insert( - it.index(), std::make_pair(std::forward<K>(key), std::forward<V>(value))); - } - - return set<map>(std::forward<S>(storage), std::forward<K>(key), std::forward<V>(value)); -} - -template <typename map, typename S, typename K> -[[nodiscard]] typename map::storage_type erase(S&& storage, K&& key) { - auto it = find<map>(storage, key); - if (it == storage.end()) { - return std::forward<S>(storage); - } - return std::forward<S>(storage).erase(it.index()); -} - -template <typename map, typename S, typename K> -[[nodiscard]] typename map::storage_type erase(S&& storage, typename map::iterator it, K&& key) { - if (it == storage.end() || !equal<map>(it->first, key)) { - return erase<map>(std::forward<S>(storage), std::forward<K>(key)); - } - return std::forward<S>(storage).erase(it.index()); -} - -} // namespace mongo::immutable::details::map diff --git a/src/mongo/util/immutable/details/memory_policy.h b/src/mongo/util/immutable/details/memory_policy.h deleted file mode 100644 index 01923f032b7..00000000000 --- a/src/mongo/util/immutable/details/memory_policy.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (C) 2023-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include <immer/memory_policy.hpp> - -namespace mongo::immutable::detail { - -// Memory allocations using regular new/delete operators -using HeapPolicy = immer::heap_policy<immer::cpp_heap>; - -// Refcounting using atomics for thread safety -using RefcountPolicy = immer::refcount_policy; - -// We are not using any features from immer that requires locking. Use 'void' as the lock type which -// would fail compilation if locking was needed anywhere. -using LockPolicy = void; - -// No transience policy (this is just used for garbage collection) -using TransiencePolicy = immer::no_transience_policy; - -using MemoryPolicy = immer::memory_policy<HeapPolicy, - RefcountPolicy, - LockPolicy, - TransiencePolicy, - /*PreferFewerBiggerObjects*/ true, - /*UseTransientRValues*/ true>; - -// Verify that the recommended settings for our memory policy is as expected. We need to investigate -// if any of these fire during a library upgrade. -static_assert( - std::is_same<immer::get_transience_policy_t<RefcountPolicy>, TransiencePolicy>::value); -static_assert(immer::get_prefer_fewer_bigger_objects_v<HeapPolicy> == true); -static_assert(immer::get_use_transient_rvalues_v<RefcountPolicy> == true); - -} // namespace mongo::immutable::detail diff --git a/src/mongo/util/immutable/details/set.h b/src/mongo/util/immutable/details/set.h deleted file mode 100644 index 491412e696f..00000000000 --- a/src/mongo/util/immutable/details/set.h +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright (C) 2023-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#include <algorithm> - -namespace mongo::immutable::details::set { - -template <typename set, typename SearchKey> -bool equal(const typename set::key_type& a, const SearchKey& b) { - return !typename set::comp{}(a, b) && !typename set::comp{}(b, a); -} - -template <typename set, class SearchKey> -[[nodiscard]] typename set::iterator lower_bound(const typename set::storage_type& storage, - const SearchKey& key) { - return std::lower_bound(storage.begin(), storage.end(), key, typename set::comp{}); -} - -template <typename set, typename SearchKey> -[[nodiscard]] typename set::iterator find(const typename set::storage_type& storage, - const SearchKey& key) { - auto it = lower_bound<set>(storage, key); - if (it != storage.end() && equal<set>(*it, key)) { - return it; - } - - return storage.end(); -} - -template <typename set, typename S, typename K> -[[nodiscard]] typename set::storage_type insert(S&& storage, K&& key) { - auto it = lower_bound<set>(storage, key); - if (it == storage.end()) { - return std::forward<S>(storage).push_back(std::forward<K>(key)); - } - - if (equal<set>(*it, key)) { - return std::forward<S>(storage); - } - - return std::forward<S>(storage).insert(it.index(), std::forward<K>(key)); -} - -template <typename set, typename S, typename K> -[[nodiscard]] typename set::storage_type insert(S&& storage, typename set::iterator it, K&& key) { - if (it != storage.end() && equal<set>(*it, key)) { - return std::forward<S>(storage); - } - - if (it == storage.end()) { - if (typename set::comp{}(storage[storage.size() - 1], key)) { - return std::forward<S>(storage).push_back(std::forward<K>(key)); - } - return insert<set>(std::forward<S>(storage), std::forward<K>(key)); - } - - if (typename set::comp{}(key, *it) && - (it.index() == 0 || typename set::comp{}(*(it - 1), key))) { - return std::forward<S>(storage).insert(it.index(), std::forward<K>(key)); - } - - return insert<set>(std::forward<S>(storage), std::forward<K>(key)); -} - -template <typename set, typename S, typename K> -[[nodiscard]] typename set::storage_type erase(S&& storage, K&& key) { - auto it = find<set>(storage, key); - if (it == storage.end()) { - return std::forward<S>(storage); - } - return std::forward<S>(storage).erase(it.index()); -} - -template <typename set, typename S, typename K> -[[nodiscard]] typename set::storage_type erase(S&& storage, typename set::iterator it, K&& key) { - if (it == storage.end() || !equal<set>(*it, key)) { - return erase<set>(std::forward<S>(storage), std::forward<K>(key)); - } - return std::forward<S>(storage).erase(it.index()); -} - -} // namespace mongo::immutable::details::set |
