Question

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

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top