adamhooper / js-sorted-set

Sorted set data structures in JavaScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sortedset length

PongPong opened this issue · comments

commented

How can I get the sortedset length or size()?

Good question :). We should add a method for it.

In the meantime, you can do something like this:

var it = set.beginIterator().next();
var size = 0;
while (it != null) {
  size += 1;
  it = it.next();
}

Finding the size is an O(n) operation right now. I'll make it O(1) when I get around to fixing this issue :).

Upgrade to v0.1.0 and you can just use var len = set.length;.

Sorry for the delay :).