Changeset b9076db in mainline


Ignore:
Timestamp:
2018-07-05T21:41:21Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6562af2
Parents:
5ae8168
git-author:
Dzejrou <dzejrou@…> (2018-04-25 17:38:45)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
Message:

cpp: added copy/move constructor/assignment to the hash table

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/internal/hash_table.hpp

    r5ae8168 rb9076db  
    720720            { /* DUMMY BODY */ }
    721721
    722             // TODO: copy/move constructor/assignment operator
     722            hash_table(const hash_table& other)
     723                : hash_table{other.bucket_count_, other.hasher_, other.key_eq_,
     724                             other.max_load_factor_}
     725            {
     726                for (const auto& x: other)
     727                {
     728                    auto spot = find_insertion_spot(key_extractor_(x));
     729                    insert(spot, x);
     730                }
     731            }
     732
     733            hash_table(hash_table&& other)
     734                : table_{other.table_}, bucket_count_{other.bucket_count_},
     735                  size_{other.size_}, hasher_{move(other.hasher_)},
     736                  key_eq_{move(other.key_eq_)}, key_extractor_{move(other.key_extractor_)},
     737                  max_load_factor_{other.max_load_factor_}
     738            {
     739                other.table_ = nullptr;
     740                other.bucket_count_ = size_type{};
     741                other.size_ = size_type{};
     742                other.max_load_factor_ = 1.f;
     743            }
     744
     745            hash_table& operator=(const hash_table& other)
     746            {
     747                hash_table tmp{other};
     748                tmp.swap(*this);
     749
     750                return *this;
     751            }
     752
     753            hash_table& operator=(hash_table&& other)
     754            {
     755                hash_table tmp{move(other)};
     756                tmp.swap(*this);
     757
     758                return *this;
     759            }
    723760
    724761            bool empty() const noexcept
     
    10131050                    count = size_ / max_load_factor_;
    10141051
    1015                 // Note: This is the only place where an exception can be
    1016                 //       thrown (no mem) in this function, so wrap it
    1017                 //       in try-catch-rethrow.
     1052                /**
     1053                 * Note: If an exception is thrown, there
     1054                 *       is no effect. Since this is the only
     1055                 *       place where an exception (no mem) can
     1056                 *       be thrown and no changes to this have been
     1057                 *       made, we're ok.
     1058                 */
    10181059                hash_table new_table{count, max_load_factor_};
    10191060
Note: See TracChangeset for help on using the changeset viewer.