Changeset e912cdf in mainline for uspace/lib/cpp/include/internal


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

cpp: refactored unordered_map's insertion functions and moved some logic to the underlying hash table, added rehashing to insertion when it's needed

File:
1 edited

Legend:

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

    red9df7d re912cdf  
    10021002            void max_load_factor(float factor)
    10031003            {
    1004                 /**
    1005                  * Note: According to the standard, this function
    1006                  *       can have no effect.
    1007                  */
    1008                 // TODO: change max factor and rehash if needed
     1004                if (factor > 0.f)
     1005                    max_load_factor_ = factor;
     1006
     1007                rehash_if_needed();
    10091008            }
    10101009
     
    10811080            }
    10821081
    1083             void set_hint(const_iterator hint)
    1084             {
    1085                 // TODO: hint_ should be a ptr and we extract it here,
    1086                 //       then set it to nullptr after each operation
    1087             }
    1088 
    10891082            hint_type find_insertion_spot(const key_type& key)
    10901083            {
     
    11291122            {
    11301123                ++size_;
     1124
     1125                rehash_if_needed();
     1126            }
     1127
     1128            void decrement_size()
     1129            {
     1130                --size_;
     1131            }
     1132
     1133            node_type* find_node_or_return_head(const key_type& key,
     1134                                                const hash_table_bucket<value_type, size_type>& bucket)
     1135            {
     1136                if (bucket.head)
     1137                {
     1138                    auto head = bucket.head;
     1139                    auto current = bucket.head;
     1140
     1141                    do
     1142                    {
     1143                        if (keys_equal(key, current->value))
     1144                            return current;
     1145                        else
     1146                            current = current->next;
     1147                    }
     1148                    while (current != head);
     1149
     1150                    return head;
     1151                }
     1152                else
     1153                    return nullptr;
    11311154            }
    11321155
Note: See TracChangeset for help on using the changeset viewer.