Back to Aptos Core

Module `0x1::cmp`

aptos-move/framework/move-stdlib/doc/cmp.md

latest7.8 KB
Original Source

<a id="0x1_cmp"></a>

Module 0x1::cmp

<pre><code></code></pre>

<a id="0x1_cmp_Ordering"></a>

Enum Ordering

<pre><code>enum <a href="cmp.md#0x1_cmp_Ordering">Ordering</a> <b>has</b> <b>copy</b>, drop </code></pre> <details> <summary>Variants</summary> <details> <summary>Less</summary> <details> <summary>Fields</summary> <dl> </dl> </details> </details> <details> <summary>Equal</summary> <details> <summary>Fields</summary> <dl> </dl> </details> </details> <details> <summary>Greater</summary> <details> <summary>Fields</summary> <dl> </dl> </details> </details> </details>

<a id="0x1_cmp_compare"></a>

Function compare

Compares two values with the natural ordering:

  • native types are compared identically to <code><</code> and other operators
  • complex types
  • Structs and vectors - are compared lexicographically - first field/element is compared first, and if equal we proceed to the next.
  • enum's are compared first by their variant, and if equal - they are compared as structs are.
<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_compare">compare</a>&lt;T&gt;(first: &T, second: &T): <a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a> </code></pre> <details> <summary>Implementation</summary> <pre><code><b>native</b> <b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_compare">compare</a>&lt;T&gt;(first: &T, second: &T): <a href="cmp.md#0x1_cmp_Ordering">Ordering</a>; </code></pre> </details>

<a id="0x1_cmp_is_eq"></a>

Function is_eq

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_eq">is_eq</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_eq">is_eq</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool { self is Ordering::Equal } </code></pre> </details>

<a id="0x1_cmp_is_ne"></a>

Function is_ne

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_ne">is_ne</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_ne">is_ne</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool { !(self is Ordering::Equal) } </code></pre> </details>

<a id="0x1_cmp_is_lt"></a>

Function is_lt

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_lt">is_lt</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_lt">is_lt</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool { self is Ordering::Less } </code></pre> </details>

<a id="0x1_cmp_is_le"></a>

Function is_le

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_le">is_le</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_le">is_le</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool { !(self is Ordering::Greater) } </code></pre> </details>

<a id="0x1_cmp_is_gt"></a>

Function is_gt

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_gt">is_gt</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_gt">is_gt</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool { self is Ordering::Greater } </code></pre> </details>

<a id="0x1_cmp_is_ge"></a>

Function is_ge

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_ge">is_ge</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <details> <summary>Implementation</summary> <pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_ge">is_ge</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">Ordering</a>): bool { !(self is Ordering::Less) } </code></pre> </details>

<a id="@Specification_0"></a>

Specification

<a id="@Specification_0_Ordering"></a>

Enum Ordering

<pre><code>enum <a href="cmp.md#0x1_cmp_Ordering">Ordering</a> <b>has</b> <b>copy</b>, drop </code></pre> <dl> <details> <summary>Less</summary> <details> <summary>Fields</summary> <dl> </dl> </details> </details> <details> <summary>Equal</summary> <details> <summary>Fields</summary> <dl> </dl> </details> </details> <details> <summary>Greater</summary> <details> <summary>Fields</summary> <dl> </dl> </details> </details> </dl> <pre><code><b>pragma</b> intrinsic; </code></pre>

<a id="@Specification_0_compare"></a>

Function compare

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_compare">compare</a>&lt;T&gt;(first: &T, second: &T): <a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a> </code></pre> <pre><code><b>pragma</b> intrinsic; </code></pre>

<a id="@Specification_0_is_eq"></a>

Function is_eq

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_eq">is_eq</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <pre><code><b>pragma</b> intrinsic; <b>pragma</b> opaque; <b>pragma</b> verify = <b>false</b>; </code></pre>

<a id="@Specification_0_is_ne"></a>

Function is_ne

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_ne">is_ne</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <pre><code><b>pragma</b> intrinsic; <b>pragma</b> opaque; <b>pragma</b> verify = <b>false</b>; </code></pre>

<a id="@Specification_0_is_lt"></a>

Function is_lt

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_lt">is_lt</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <pre><code><b>pragma</b> intrinsic; <b>pragma</b> opaque; <b>pragma</b> verify = <b>false</b>; </code></pre>

<a id="@Specification_0_is_le"></a>

Function is_le

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_le">is_le</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <pre><code><b>pragma</b> intrinsic; <b>pragma</b> opaque; <b>pragma</b> verify = <b>false</b>; </code></pre>

<a id="@Specification_0_is_gt"></a>

Function is_gt

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_gt">is_gt</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <pre><code><b>pragma</b> intrinsic; <b>pragma</b> opaque; <b>pragma</b> verify = <b>false</b>; </code></pre>

<a id="@Specification_0_is_ge"></a>

Function is_ge

<pre><code><b>public</b> <b>fun</b> <a href="cmp.md#0x1_cmp_is_ge">is_ge</a>(self: &<a href="cmp.md#0x1_cmp_Ordering">cmp::Ordering</a>): bool </code></pre> <pre><code><b>pragma</b> intrinsic; <b>pragma</b> opaque; <b>pragma</b> verify = <b>false</b>; </code></pre>