Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Module 0x1::cmp

Enum Ordering

enum Ordering has copy, drop
Variants
Less
Fields
Equal
Fields
Greater
Fields

Function compare

Compares two values with the natural ordering:

  • native types are compared identically to < 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.
public fun compare<T>(first: &T, second: &T): cmp::Ordering
Implementation
native public fun compare<T>(first: &T, second: &T): Ordering;

Function is_eq

public fun is_eq(self: &cmp::Ordering): bool
Implementation
public fun is_eq(self: &Ordering): bool {
    self is Ordering::Equal
}

Function is_ne

public fun is_ne(self: &cmp::Ordering): bool
Implementation
public fun is_ne(self: &Ordering): bool {
    !(self is Ordering::Equal)
}

Function is_lt

public fun is_lt(self: &cmp::Ordering): bool
Implementation
public fun is_lt(self: &Ordering): bool {
    self is Ordering::Less
}

Function is_le

public fun is_le(self: &cmp::Ordering): bool
Implementation
public fun is_le(self: &Ordering): bool {
    !(self is Ordering::Greater)
}

Function is_gt

public fun is_gt(self: &cmp::Ordering): bool
Implementation
public fun is_gt(self: &Ordering): bool {
    self is Ordering::Greater
}

Function is_ge

public fun is_ge(self: &cmp::Ordering): bool
Implementation
public fun is_ge(self: &Ordering): bool {
    !(self is Ordering::Less)
}

Specification

Enum Ordering

enum Ordering has copy, drop
Less
Fields
Equal
Fields
Greater
Fields
pragma intrinsic;

Function compare

public fun compare<T>(first: &T, second: &T): cmp::Ordering
pragma intrinsic;

Function is_eq

public fun is_eq(self: &cmp::Ordering): bool
pragma intrinsic;
pragma opaque;
pragma verify = false;

Function is_ne

public fun is_ne(self: &cmp::Ordering): bool
pragma intrinsic;
pragma opaque;
pragma verify = false;

Function is_lt

public fun is_lt(self: &cmp::Ordering): bool
pragma intrinsic;
pragma opaque;
pragma verify = false;

Function is_le

public fun is_le(self: &cmp::Ordering): bool
pragma intrinsic;
pragma opaque;
pragma verify = false;

Function is_gt

public fun is_gt(self: &cmp::Ordering): bool
pragma intrinsic;
pragma opaque;
pragma verify = false;

Function is_ge

public fun is_ge(self: &cmp::Ordering): bool
pragma intrinsic;
pragma opaque;
pragma verify = false;