Đang chuẩn bị liên kết để tải về tài liệu:
The C++ Programming Language Third Edition phần 6
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Không giống như m ap h, p như h_ ma không dựa trên một bài kiểm tra bình đẳng tổng hợp từ một hoạt động ít hơn ma p, ha sh _m ap (§ 17.1.4.1). Điều này là bởi vì các cuộc gọi của eq () trong vòng lặp thông qua các yếu tố với giá trị băm như eq. | Section 17.6.2.1 Lookup 501 not found if b .size max _load V .size if toofull re s ize b. size grow grow return operator k rehash V .push_back Entry k default_value b i add Entry b i V . back point to new element return b i - val Unlike map hash_map doesn t rely on an equality test synthesized from a less-than operation 17.1.4.1 . This is because of the call of eq in the loop that looks through elements with the same hash value. This loop is crucial to the performance of the lookup and for common and obvious key types such as string and C-style strings the overhead of an extra comparison could be significant. I could have used a set Entry to represent the set of values that have the same hash value. However if we have a good hash function h ash and an appropriately-sized hash table b most such sets will have exactly one element. Consequently I linked the elements of that set together using the next field of Entry 17.8 27 . Note that b keeps pointers to elements of V and that elements are added to V. In general push_back can cause reallocation and thus invalidate pointers to elements 16.3.5 . However in this case constructors 17.6.2 and resize carefully reserVe enough space so that no unexpected reallocation happens. 17.6.2.2 Erase and Rehash cont.hash.erase Hashed lookup becomes inefficient when the table gets too full. To lower the chance of that happening the table is automatically resize d by the subscript operator. The set _load 17.6.2 provides a way of controlling when and how resizing happens. Other functions are provided to allow a programmer to observe the state of a h ash_m ap template class Key class T class H Hash Key class EQ equal_to Key class A allocator T class hash_map . Void resize size _type n make the size of the hash table n Void erase iterator position erase the element pointed to size _type size const re turn V. size -no_of_erased number of elements size _type bu cke t_coun t const re tu rn b. size size of hash table Hashe r hash_fun const .