HashMultiMap save repetitive keys bindings on background?

192 views Asked by At

why when table.Count = 1 table iteration functions get more than 1 key-value pairs? And if this is feature how can I expected behavior?

//
            let table = new HashMultiMap<string, int> (HashIdentity.Structural)
            table.Add("a", 1)
            table.Add("a", 1)
            table.Add("a", 1)
            // now table.Count is one
            let reduced = table.Fold (fun k v acc -> (k,v) :: acc) [] 
            let acc = ref []
            table.Iterate (fun k v -> acc.contents <- (k,v) :: acc.contents)
            //  

reduced and acc.contents contains three ("a",1) pairs

1

There are 1 answers

2
Tomas Petricek On BEST ANSWER

The documentation for the Count member says:

The total number of keys in the hash table

If you have multiple values associated with the same key, there is still only a single key, so the value 1 is the expected result for your example. As far as I can see, there is no property that returns the total number of values, but you can implement that easily using Fold:

let valueCount = table.Fold (fun _ _ n -> n + 1) 0