Size with a Hash

class SizedHash<T> extends Hash<T> {
  public var size(default, null): Int;

  public function new() { super(); size = 0; }

  public override function set(key: String, val:T) : Void {
    if (! exists(key)) size++;
    super.set(key, val);

  public override function remove(key) : Bool {
    if (exists(key)) size--;
    return super.remove(key);

A simple Hash subclass that registers the number of elements within a Hash, by means of the read-only parameter size.

version #7035, modified 2009-09-23 16:06:15 by mloots