| 782 | } |
| 783 | |
| 784 | func (m *Map[K, V]) delete(key K, mutable bool) *Map[K, V] { |
| 785 | // Return original map if no keys exist. |
| 786 | if m.root == nil { |
| 787 | return m |
| 788 | } |
| 789 | |
| 790 | // If the delete did not change the node then return the original map. |
| 791 | var resized bool |
| 792 | newRoot := m.root.delete(key, 0, m.hasher.Hash(key), m.hasher, mutable, &resized) |
| 793 | if !resized { |
| 794 | return m |
| 795 | } |
| 796 | |
| 797 | // Generate copy if necessary. |
| 798 | other := m |
| 799 | if !mutable { |
| 800 | other = m.clone() |
| 801 | } |
| 802 | |
| 803 | // Return copy of map with new root and decreased size. |
| 804 | other.size = m.size - 1 |
| 805 | other.root = newRoot |
| 806 | return other |
| 807 | } |
| 808 | |
| 809 | // Iterator returns a new iterator for the map. |
| 810 | func (m *Map[K, V]) Iterator() *MapIterator[K, V] { |