Changeset 86d1939 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:
c439e6a
Parents:
86b3ae98
git-author:
Dzejrou <dzejrou@…> (2018-04-24 21:12:53)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
Message:

cpp: fixed compilation errors, added bodies of some functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/unordered_map.hpp

    r86b3ae98 r86d1939  
    3131
    3232#include <initializer_list>
    33 #include <internal/hash_map.hpp>
     33#include <internal/hash_table.hpp>
    3434#include <functional>
    3535#include <memory>
     
    4343
    4444    template<
    45         class Key, class Value
     45        class Key, class Value,
    4646        class Hash = hash<Key>,
    4747        class Pred = equal_to<Key>,
     
    8181            { /* DUMMY BODY */ }
    8282
    83             explicit unordered_map(size_type bucket_count = default_bucket_count_,
     83            explicit unordered_map(size_type bucket_count,
    8484                                   const hasher& hf = hasher{},
    8585                                   const key_equal& eql = key_equal{},
     
    9696                : unordered_map{bucket_count, hf, eql, alloc}
    9797            {
    98                 // TODO: insert the range
     98                insert(first, last);
    9999            }
    100100
     
    126126                : unordered_map{bucket_count, hf, eql, alloc}
    127127            {
    128                 // TODO: insert the range
     128                insert(init.begin(), init.end());
    129129            }
    130130
     
    179179            unordered_map& operator=(initializer_list<value_type>& init)
    180180            {
    181                 // TODO: implement
     181                table_.clear();
     182                table_.reserve(init.size());
     183
     184                insert(init.begin(), init.end());
     185
    182186                return *this;
    183187            }
     
    338342            iterator erase(const_iterator position)
    339343            {
    340                 // TODO: implement
     344                return table_.erase(position);
    341345            }
    342346
    343347            size_type erase(const key_type& key)
    344348            {
    345                 // TODO: implement
     349                return table_.erase(key);
    346350            }
    347351
    348352            iterator erase(const_iterator first, const_iterator last)
    349353            {
    350                 // TODO: implement
     354                while (first != last)
     355                    first = erase(first);
     356
     357                return iterator{
     358                    table_.table(), first.idx(),
     359                    table_.size(), table_.head(first.idx())
     360                };
    351361            }
    352362
     
    377387            iterator find(const key_type& key)
    378388            {
    379                 // TODO: implement
     389                return table_.find(key);
    380390            }
    381391
    382392            const_iterator find(const key_type& key) const
    383393            {
    384                 // TODO: implement
     394                return table_.find(key);
    385395            }
    386396
    387397            size_type count(const key_type& key) const
    388398            {
    389                 // TODO: implement
     399                return table_.count(key);
    390400            }
    391401
    392402            pair<iterator, iterator> equal_range(const key_type& key)
    393403            {
    394                 // TODO: implement
     404                return table_.equal_range(key);
    395405            }
    396406
    397407            pair<const_iterator, const_iterator> equal_range(const key_type& key) const
    398408            {
    399                 // TODO: implement
     409                return table_.equal_range(key);
    400410            }
    401411
    402412            mapped_type& operator[](const key_type& key)
    403413            {
    404                 // TODO: implement
     414                auto spot = table_.find_insertion_spot(key);
     415                auto bucket = get<0>(spot);
     416
     417                if (bucket->head)
     418                {
     419                    auto head = bucket->head;
     420                    auto current = bucket->head;
     421
     422                    do
     423                    {
     424                        if (table_.keys_equal(key, current->value))
     425                            return current->value.second;
     426                        else
     427                            current = current->next;
     428                    }
     429                    while (current != head);
     430                }
     431
     432                bucket->append(new node_type{key, mapped_type{}});
     433
     434                return bucket->head->value.second;
    405435            }
    406436
    407437            mapped_type& operator[](key_type&& key)
    408438            {
    409                 // TODO: implement
     439                auto spot = table_.find_insertion_spot(key);
     440                auto bucket = get<0>(spot);
     441
     442                if (bucket->head)
     443                {
     444                    auto head = bucket->head;
     445                    auto current = bucket->head;
     446
     447                    do
     448                    {
     449                        if (table_.keys_equal(key, current->value))
     450                            return current->value.second;
     451                        else
     452                            current = current->next;
     453                    }
     454                    while (current != head);
     455                }
     456
     457                bucket->append(new node_type{move(key), mapped_type{}});
     458
     459                return bucket->head->value.second;
    410460            }
    411461
     
    496546
    497547        private:
    498             aux::hash_map<
     548            using table_type = aux::hash_table<
    499549                value_type, key_type, aux::key_value_key_extractor<key_type, mapped_type>,
    500550                hasher, key_equal, allocator_type, size_type,
    501551                iterator, const_iterator, local_iterator, const_local_iterator,
    502552                aux::hash_single_policy
    503             > table_;
    504 
     553            >;
     554            using node_type = typename table_type::node_type;
     555
     556            table_type table_;
    505557            allocator_type allocator_;
    506558
     
    513565
    514566    template<
    515         class Key, class Value
     567        class Key, class Value,
    516568        class Hash = hash<Key>,
    517569        class Pred = equal_to<Key>,
Note: See TracChangeset for help on using the changeset viewer.