In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
, the augmented map
is an
abstract data type (ADT) based on ordered
maps, which associates each ordered map an augmented value. For an ordered map
with key type
, comparison function
on
and value type
, the augmented value is defined based on two functions: a ''base'' function
and a ''combine'' function
, where
is the type of the augmented value. The base function
converts a single entry in
to an augmented value, and the combine function
combines multiple augmented values. The combine function
is required to be
associative
In mathematics, the associative property is a property of some binary operations, which means that rearranging the parentheses in an expression will not change the result. In propositional logic, associativity is a valid rule of replacement ...
and have an
identity (i.e.,
forms a
monoid
In abstract algebra, a branch of mathematics, a monoid is a set equipped with an associative binary operation and an identity element. For example, the nonnegative integers with addition form a monoid, the identity element being 0.
Monoids ...
). We extend the definition of the associative function
as follows:
Then the augmented value of an ordered map
is defined as follows:
Accordingly, an augmented map can be formally defined as a seven-tuple
. For example, an augmented map with integral keys and values, on which the augmented value is defined as the sum of all values in the map, is defined as:
As an abstract data type, the augmented map is often used to model problems and serves as an abstraction with a useful interface. It is designed for supporting fast range sums, which means to quickly return the augmented value of all entries in a certain key range.
Interface
In addition to the interface for a standard ordered map, the augmented map should also support functions for range sums. In particular:
*aug_left
: returns the augmented value of all entries in
with keys no more than
.
*aug_right
: returns the augmented value of all entries in
with keys no less than
.
*aug_range
: returns the augmented value of all entries in
with keys in range