Augmented map
In computer science, the augmented map[1] 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 and have an identity (i.e., forms a monoid). 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[edit]
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 .
- aug_val: returns the augmented value of all entries in .
Some functions, although are not defined based on augmented values, can make use of augmented values to accelerate their algorithms. Usually, they would require some certain representation of augmented maps, and certain conditions for input parameters.
- aug_filter: returns all entries in satisfying the indicator . It is only applicable when . In this case, the aug_filter function is equivalent to filter, where and . When the augmented map is implemented using augmented trees, this function can be implemented asymptotically more efficient than the naive implementation.
- aug_project: returns . Here , . It requires to be a monoid and . This function is useful when the augmented values
are themselves maps or other large data structures. It allows projecting the augmented values down onto another type by (e.g. project augmented values with complicated structures to values like their sizes) then summing them by , and is much more efficient when applicable.
Implementation[edit]
Augmented trees[edit]
The augmented map can be supported efficiently by augmented trees, where each tree node is augmented by the augmented value of all entries in its subtree. Because of the associativity of the combine function , the augmented value of a certain tree is fixed, and is independent of the shape of the tree, regardless of rotations. In this case, by combining the partial sums in the tree nodes, any range sum can be returned in time on an augmented map of size , assuming both and have constant cost. For aug_filter, the tree structure takes the advantage that if the augmented value of a subtree does not satisfy the indicator , the whole tree gets discarded. In this case, the cost of aug_filter is where is the output size. For aug_project, whenever a whole subtree falls in the range , its augmented value can be directly combined to the result, instead of requiring traversing the tree.
Prefix structures[edit]
Another implementation is to use prefix structures,[2] which stores the augmented value of all prefixes of the map. For the above-defined augmented map , the prefix structure is an array stored the prefix sum of the values, sorted by their keys. Prefix structures are particularly useful for aug_left, but can be inefficient to implement other functions on the augmented map interface. It can be useful in some geometric algorithms.
Example application[edit]
1D stabbing query[edit]
A 1D stabbing query takes as input a set of intervals on 1D number line. The query asks for if a given point is covered by any input interval, or all intervals covering this point. An augmented map can be defined for this problem, where the keys are the left endpoints of all intervals, values are the corresponding right endpoints, and the augmented value is the maximum value of all right endpoints in the map. More formally:
To report if any interval covers a given point , the query algorithm simply determines if aug_left. This is because aug_left looks at all intervals that start before , and if the maximum right endpoint among them exceeds , then must be covered. When implemented with augmented trees, the augmented map is exactly an interval tree. Constructing such an augmented tree structure costs work , parallel depth and space. Each stabbing query can be done in time .
2D range query[edit]
A 2D range query takes as input a set of points on 2 dimensions. The query asks for all points (or the number) in a certain rectangle, whose edges are parallel to the axis. An augmented map can be defined for this problem, which is a two-level nested map structure. The outer map stores all points and sort them by their x-coordinates. The augmented value of the outer map is an inner augmented map structure, which stores the same set of points as the outer map, but sorts them by their y-coordinates. The augmentation of the inner trees accumulate the count of points, i.e., the augmented value of an inner map is its size. Accordingly, the combine function of the outer map is to take a union of the two inner augmented maps. More formally:
Here for simplicity, assume all coordinates are unique. and are the types of the x- and y-coordinates. To answer the range query in rectangle , the query algorithm extracts the augmented value of the outer map in the key range , which is an inner map of all desired points sorted by y-coordinates. Therefore, the algorithm takes another aug_range on this inner map and gets the result. For counting queries, the algorithm can make use of the aug_project function.
If both the inner and the outer maps are implemented by augmented trees, then the whole two-level map structure becomes a range tree structure. If the inner map is supported by the augmented tree structure, and the outer tree is supported as the prefix structure, then the algorithm becomes a sweepline algorithm.
Other examples[edit]
Other examples[1][2] include segment queries, inverted index searching, rectangle queries, etc.
Library support[edit]
A parallel implementation of the augmented map interface is provided in a library PAM.
Notes[edit]
References[edit]
- ↑ 1.0 1.1 Blelloch, Guy E.; Ferizovic, Daniel; Sun, Yihan (2018), "PAM: parallel augmented maps", Proceedings of the 23rd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, ACM, pp. 290–304
- ↑ 2.0 2.1 Blelloch, Guy E.; Sun, Yihan (2018), "Parallel Range, Segment and Rectangle Queries with Augmented Maps", Parallel Range, Segment and Rectangle Queries with Augmented Maps
This article "Augmented map" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Augmented map. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.