### Preliminary PRs: - [x] #4597 - [x] #4599 - [x] #4600 - [x] #4602 - [x] #4603 - [x] #4604 - [x] #4605 - [x] #4607 - [x] #4627 - [x] #4629 ### Quick overview over API/naming changes compared to `Lean.HashMap` and `Batteries.HashMap`: #### Lean * `find?` -> `get?`/`getElem?` * `find!` -> `get!`/`gtetElem!` * `findD` -> `getD` * `findEntry?` -> not implemented for now * `insert'` -> `containsThenInsert` (order reversed in result) * `insertIfNew` -> `getThenInsertIfNew?` (order reversed in result) * `numBuckets` -> `Internal.numBuckets` * `ofListWith` -> not implemented for now * `Array.groupByKey` -> not implemented for now * `merge` -> not implemented for now, but you can use `insertMany` #### Batteries * `modify` -> not implemented for now * `mergeWith` -> not implemented for now * `mergeWithM` -> not implemented for now
50 lines
1.3 KiB
Text
50 lines
1.3 KiB
Text
/-
|
||
Copyright (c) 2024 Lean FRO, LLC. All rights reserved.
|
||
Released under Apache 2.0 license as described in the file LICENSE.
|
||
Authors: Markus Himmel
|
||
-/
|
||
prelude
|
||
import Std.Data.DHashMap.AdditionalOperations
|
||
import Std.Data.HashMap.Basic
|
||
import Std.Data.HashMap.Raw
|
||
|
||
/-!
|
||
# Additional hash map operations
|
||
|
||
This module defines the operations `map` and `filterMap` on `Std.Data.HashMap`.
|
||
We currently do not provide lemmas for these functions.
|
||
-/
|
||
|
||
set_option linter.missingDocs true
|
||
set_option autoImplicit false
|
||
|
||
universe u v w
|
||
|
||
variable {α : Type u} {β : Type v} {γ : Type w}
|
||
|
||
namespace Std
|
||
|
||
namespace HashMap
|
||
|
||
namespace Raw
|
||
|
||
theorem WF.filterMap [BEq α] [Hashable α] {m : Raw α β} {f : α → β → Option γ} (h : m.WF) :
|
||
(m.filterMap f).WF :=
|
||
⟨DHashMap.Raw.WF.filterMap h.out⟩
|
||
|
||
theorem WF.map [BEq α] [Hashable α] {m : Raw α β} {f : α → β → γ} (h : m.WF) : (m.map f).WF :=
|
||
⟨DHashMap.Raw.WF.map h.out⟩
|
||
|
||
end Raw
|
||
|
||
@[inline, inherit_doc DHashMap.filterMap] def filterMap [BEq α] [Hashable α] (f : α → β → Option γ)
|
||
(m : HashMap α β) : HashMap α γ :=
|
||
⟨m.inner.filterMap f⟩
|
||
|
||
@[inline, inherit_doc DHashMap.map] def map [BEq α] [Hashable α] (f : α → β → γ) (m : HashMap α β) :
|
||
HashMap α γ :=
|
||
⟨m.inner.map f⟩
|
||
|
||
end HashMap
|
||
|
||
end Std
|