For context I'm creating my own hashmap in swift.
I've got an element and I'm storing the elements in buckets which is an array of arrays
struct Element {
var key: Int
var value: Int
}
class MyHashMap {
var buckets : [[Element]] = [[]]
init() {
buckets = [Array(repeating: Element(key: -1, value: -1), count: 2)]
buckets.append([Element(key: 3, value: 4)])
}
}
I want to remove all the buckets where the key is -1 and I'm struggling.
Flatmap does not return the right type i.e.
hashmap.buckets.flatMap{$0}.filter{$0.key != -1}
is incorrect.
How can I remove all of the buckets with key -1?