Counter

Implementation of a counter.

Counter:__init()

View source

Constructor.

Counter:add(key, count)

View source

Increments the count for a key.

Arguments:

  • key (any): key to increment count for.
  • count (int): how much to increment count by.

Returns:

  • (int) the new count

Counter:get(key)

View source

Arguments:

  • key (any): key to return count for.

Returns:

  • (int) the count for the key

If key has not been added to the counter, then returns 0.

Counter:reset()

View source

Clears the counter.

Returns:

  • (Counter) the modified counter