MCPcopy Create free account
hub / github.com/benbjohnson/immutable / delete

Method delete

immutable.go:784–807  ·  view source on GitHub ↗
(key K, mutable bool)

Source from the content-addressed store, hash-verified

782}
783
784func (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.
810func (m *Map[K, V]) Iterator() *MapIterator[K, V] {

Callers 1

DeleteMethod · 0.95

Calls 7

cloneMethod · 0.95
indexOfMethod · 0.95
deleteMethod · 0.65
HashMethod · 0.65
EqualMethod · 0.65
minKeyMethod · 0.65
CompareMethod · 0.65

Tested by

no test coverage detected