Since sets are commonly used in esProc, the latter provides comprehensive set operations.
1. Binary Operation on Sets
The most basic set in esProc is sequence. Let’s look at some basic binary operations between two sequences A and B.
Concatenation: Concatenate the two sequences straightforwardly. The members of B are added behind the members of A. If A or B or both A and B are single-value instead of sequences, then they will be handled as single member sequences.
Union: Join the two sequences and remove the members of B that already exist in A. If one of A and B or both are single- value instead of sequences, then you can take them as single member sequences to process.
Intersection: Intersection set of A and B. Get a sequence composed of members that not only exist in A but also exist in B.
Complement: Members in A but not in B. If B is not a sequence, then treat it as the single member sequence.
A|A|…|A, which is to concatenate the k same sequences, that is, copy A k times. Positions of k and A are interchangeable in the expression.
A2, A3, A4 and A5 compute respectively the concatenation, union, intersection and complement of the sequence in A1 and the sequence in B1:
In A6 and A7, sequence A1 is multiplied by an integer. The result is as follows:
These basic operations – concatenation, complement, intersection and union – can also be used to deal with more complex set operations. Such as, to seek the “inverse intersection” of sets A and B, i.e., the set composed of all that is not the common members of A and B.
The result of A2 is as follows:
The “inverse intersection” of two sets is the complement of their union and intersection. With this kind of transformation, more complex binary operations will be completed.
2. Alignment Arithmetic Operations on Sets
We can perform the alignment arithmetic operations on two sequences of the same length according to their members and return a new sequence.
[A(1)%B(1),A(2)%B(2),…], the % here is the Mod computation.
[A(1)\B(1),A(2)\B(2),…], the slash here means integer division.
The results of A2, A3, A4 and A5 are as follows:
3. A Comparison of Sets
In esProc, the function cmp(A,B) can be used to compare the sequence A and B.
Compare the values of members of the two sequences one by one in alignment. When the first pair of unequal members appear, return 1 if the member in A is greater than that in B; otherwise return -1. If A is identical to B, then return 0. Specifically, cmp(A) or cmp(A,0) will compare A and the sequence with the same length and with its all members being 0, i.e. cmp(A,[0,0,…,0]).
The results of A1, A2 and A3 are as follows:
The comparison of two sequences can be briefly expressed as A==B, A>B.
Note that a sequence in esProc is an ordered set, so order plays an important role in comparing if the two sequences A and B are equal. A.eq(B) is used to see if the two sequences have common members.
Because the member order in A1 and A2 is different, result in A3 is false, showing the two sequences are not equal:
While result in A4 is true, showing the two sequences have the same members: