I suggest we ...

Make Set.count O(1)

Seems easy to track items when they are added and removed

3 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Zhen shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

2 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Jack Fox commented  ·   ·  Flag as inappropriate

    You are going to incur the cost somewhere. It's usually preferable to incur it when you request count.

  • Robert Pickering commented  ·   ·  Flag as inappropriate

    Sadly, not as straight forward as it sounds, since set also support filter and partition as well as add. filter and partition work directly on the SetTree type that represents set internally, so these operation would need to return the new count. It could be done, but the question is should it be done, as the extra over heads may out weight the perf gains from have Set.count O(1). Difficult call to make imho.

F# Language

Feedback and Knowledge Base