Changeset 7320ca6 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:
1d5424a
Parents:
f67b4ef
git-author:
Dzejrou <dzejrou@…> (2018-04-23 20:33:48)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:21)
Message:

cpp: added bucket operations and changed clear to only deallocate bucket lists, but not to reallocate the bucket array

File:
1 edited

Legend:

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

    rf67b4ef r7320ca6  
    8181        Size size() const noexcept
    8282        {
    83             // TODO: implement
     83            auto current = head;
     84            Size res{};
     85
     86            do
     87            {
     88                ++res;
     89                current = current->next;
     90            }
     91            while (current != head);
     92
     93            return res;
    8494        }
    8595
     
    92102        }
    93103
     104        void clear()
     105        {
     106            auto current = head;
     107            do
     108            {
     109                auto tmp = current;
     110                current = current->next;
     111                delete tmp;
     112            }
     113            while (current != head);
     114
     115            head = nullptr;
     116        }
     117
    94118        ~hash_table_bucket()
    95119        {
    96             // TODO: deallocate the entire list
     120            clear();
    97121        }
    98122    };
     
    758782            void clear() noexcept
    759783            {
    760                 delete[] table_;
    761 
     784                for (size_type i = 0; i < bucket_count_; ++i)
     785                    table_[i].clear();
    762786                size_ = size_type{};
    763                 table_ = new hash_table_bucket<value_type, size_type>[bucket_count_];
    764787            }
    765788
Note: See TracChangeset for help on using the changeset viewer.