Functional Counters

Denys Duchier

module
x-oz://system/adt/Counter.ozf

This module provides a functional interface for counters

Exports

The modules exports 2 constructors:

{Counter.newFromInt +I ?C}
returns a new functional counter instance, initialized to integer value I
{Counter.new ?C}
return a new functional counter instance, initialized to 1

Instance API

Each functional counter instance C has the following features:

{C.get ?I}
returns the current value I of C
{C.put +I}
sets the current value of C to I
{C.getPut Old New}
atomically gets the current value Old of C and sets it to the new value New
{C.next ?I}
returns the current value I of C and increments the counter
{C.plus +N}
increments C by N
{C.times +N}
multiplies the content of C by N
{C.clone ?C2}
returns a new counter C2 currently holding the same integer value as C