invertAll
Relational functions invertAll
syntax
- invertAll(relation)
definition
invertAll(relation) inverts the relation Argument as Invert does, and adds the Subitem Next, with which all elements that map onto the same value can be visited.
For a relation with Domain unit A and Values unit B, the result is an Attribute with domain unit B and values unit A:
- the result holds for each element of B the last element of A that maps onto it, or null when no element of A does. This equals invert(relation).
- Next, an attribute with domain unit A and values unit A, holds for each element of A the previous element of A with the same relation value, or null when no earlier element has that value.
Last and previous refer to the order of the elements of A, which for a Grid Domain is row by row.
To visit all elements of A that map onto an element of B, start with the result for that element and follow Next until it is null. This visits them in descending order, from the last to the first.
An element of A for which relation is null is not visited: neither the result nor Next refers to it, and its own Next is null.
value info
For a resulting row that is null, the [[value info]] dialog reports no row of the inverted attribute refers to this row: nothing in the relation argument maps onto that element of B. For a row that does have a value, the dialog lists the elements of relation that map onto it. (since 20.16.0)
applies to
- attribute relation with Value type of the group CanBeDomainUnit
performance
Time complexity: O(n + m), where n is the number of elements of A and m the number of elements of B: the result is set to null and then filled in a single pass over relation.
Space complexity: O(n + m): Next has n values and the result m values. When one element of A per element of B suffices, Invert gives the same result without Next.
example
unit<uint32> Person: nrofrows = 5;
unit<uint32> Household: nrofrows = 3;
attribute<Household> household_rel (Person): [0, 0, 1, 2, 1];
// Person 0,1 -> Household 0; Person 2,4 -> Household 1; Person 3 -> Household 2
attribute<Person> inv (Household) := invertAll(household_rel)
{
attribute<Person> Next (Person);
}
// inv (Household) = {1, 4, 3} -- last person per household
// inv/Next (Person) = {null, 0, null, null, 2} -- previous person in the same household
// Iteration: Household 0 -> Person 1 -> Person 0 -> (null)
// Household 1 -> Person 4 -> Person 2 -> (null)
// Household 2 -> Person 3 -> (null)
see also
- Invert - the same result, without Next
- Rlookup - reverse lookup
- Relational functions
since version
5.0