feature request: add .Clear method

Open
#55 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
go
Domain
backend

Research direction

Locate the OrderedMap and list implementations, then inspect how the key-value storage and linked-list state are managed. Use the proposed Clear behavior as the starting point and verify that entries are removed, pointer references are released, and existing capacity is retained. Run the repository's existing tests to confirm current map operations still work.

Written by the indexing model from the issue text.

Description

Currently, it's impossible to clear the OrderedMap keeping its capacity.

A simple implementation would be:

func (l *list[K, V]) Clear() {
	l.root = Element[K, V]{} // just in case K & V are pointer types
}

func (m *OrderedMap[K, V]) Clear() {    
	clear(m.kv)
	m.ll.Clear()
}
Dominant language
Go
Stars
1k
Forks
77
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from elliotchance/orderedmap

All issues in elliotchance/orderedmap

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.