Description
#106 introduced HashSet
instead of Set
as the datastructure holding the “views” of the network from the POV of one node. The motivation was mainly the node identity type n
needs to carry information about the (last known) network address of a peer, in order to be able to reconnect to it. Imposing an Ord
constraint on n
seemed at least contrived.
One issue now is that HashSet
s don’t track their size, making size
O(n)
(as opposed to O(1)
for Set
); see haskell-unordered-containers/unordered-containers#138. It‘s not a big problem, since the number of elements stored is fairly small, but less than optimal because size
is used a lot.
Another not-so-nicety is that HashSet
doesn’t have an indexing function (a la elemAt
), requiring conversion to a list in order to select a random element (again occurs often in the algorithm).
Two approaches come to mind:
- Wrap
HashSet
such that it’s size is tracked (could be tricky with updates), and a separateVector
or some such is maintained for the purpose of drawing random elements. - Use an
IntMap
underneath and explicitly convert fromHashable
toInt
(Achtung: collisions)