Next: , Previous: , Up: vectors   [Index]


24.6 Comparison

Function: %vector-compare item= item< vec1 beg1 past1 vec2 beg2 past2 proc< proc= proc>
Macro: vector-compare item= item< V1 V2 proc< proc= proc>

Determine the mismatch index between the two subvectors: the largest index i such that for every 0 <= j < i, vec1[j] = vec2[j]; that is, i is the first position that does not match.

The mismatch index is always an index into vec1; in the case of equal vectors, it is always past1; the functions observe the protocol in this redundant case for uniformity.

The items before the mismatch index are tested for equality using item=; the items at the mismatch index are also compared using item<, to determine the smallest.

proc<, proc=, or proc> are applied to the mismatch index (not item), depending upon whether the subvector of vec1 is less than, equal to, or greater than the subvector of vec2. The result of the application is returned.

If we just want to have the mismatch index as return value: We can use values as value for proc<, proc= and proc>. Another interesting option is to use (lambda (mismatch-index) #f) or (lambda (mismatch-index) #t).

Examples:

(vector-compare '#(0 1 2 3) '#(0 1 2 3) values values values)
⇒ 4

(vector-compare '#(0 1 2 3) '#(0 1 2 3) values values values)
⇒ 4
Function: %vector= item= vec1 beg1 past1 vec2 beg2 past2
Macro: vector= item= V1 V2

Compare two subvectors: Return true if they are equal according to item=, #f otherwise.

Function: %vector<> item= vec1 beg1 past1 vec2 beg2 past2
Macro: vector<> item= V1 V1

Compare two subvectors: Return #f if they are equal according to item=, true otherwise.

The following predicates compare two subvectors according to the following rules:

  1. Two subvectors are equal if: they have the same length and all their items are equal according to item=.
  2. A subvector V1 is less than V2 if:
  3. A subvector V1 is greater than V2 if:
Function: %vector< item= item< vec1 beg1 past1 vec2 beg2 past2
Macro: vector< item= item< V1 V2

Compare two subvectors: Return true if the first is less than the second, #f otherwise.

Function: %vector<= item= item< vec1 beg1 past1 vec2 beg2 past2
Macro: vector<= item= item< V1 V2

Compare two subvectors: Return true if the first is less than, or equal to, the second; #f otherwise.

Function: %vector> item= item< vec1 beg1 past1 vec2 beg2 past2
Macro: vector> item= item< V1 V2

Compare two subvectors: Return true if the first is greater than the second, #f otherwise.

Function: %vector>= item= item< vec1 beg1 past1 vec2 beg2 past2
Macro: vector>= item= item< V1 V2

Compare two subvectors: Return true if the first is greater than, or equal to, the second; #f otherwise.


Next: , Previous: , Up: vectors   [Index]