Interest Protocol
  • 👋Welcome to Interest Protocol
  • Overview
    • Sui💧
      • Contracts
        • Memez
        • Libs 📚
      • Suicoins
        • Swap
        • Dollar-Cost Averaging (DCA)
        • Airdrop
          • Suiplay Airdrop
        • Incinerator
        • Send
        • Merger
        • Suicoins Terminal
      • Memez.gg
        • Coins on Memez.GG
        • Memez.Fun
          • SDK
            • Pump API
            • Interfaces
          • Configuration
          • Migrators
          • Bonding Curve
          • Fees
      • IPX Coin Standard
    • Movement
      • Interest Protocol Decentralized Exchange (DEX)
        • Key Features
        • Core Innovations
      • sr-AMM
      • Token
        • Tokenomics
        • Utility
      • GTM
    • Audits
    • Security
    • Deprecated
      • Coin X Oracle 🔮
        • Pyth Network
        • Switchboard
      • Sui Tears 💧
        • Airdrop
          • Airdrop
          • Airdrop Utils
          • Linear Vesting Airdrop
        • Capabilities
          • Access Control
          • Owner
          • Quest
          • Timelock
        • Collections
          • Bitmap
          • Coin Decimals
        • DeFi
          • Oracle
          • Farm
          • Fund
          • Linear Vesting Wallet
          • Linear Clawback Vesting Wallet
          • Vesting
        • Governance
          • DAO
          • DAO Admin
          • DAO Treasury
        • Utils
          • ASCII
          • Comparator
          • Merkle Proof
          • Vectors
        • Math
          • Fixed Point 64
          • Fixed Point Roll
          • Fixed Point Wad
          • Int
          • Math64
          • Math128
          • Math256
      • CLAMM🐚
        • Hooks
      • Whitepapers
  • Glossary
Powered by GitBook
On this page
  • Interface
  • find_upper_bound
  • lt
  • gt
  • lte
  • gte
  • ascending_insertion_sort
  • descending_insertion_sort
  • quick_sort

Was this helpful?

Export as PDF
  1. Overview
  2. Deprecated
  3. Sui Tears 💧
  4. Utils

Vectors

Utility functions for vectors.

Interface

find_upper_bound

Searches a sorted vec and returns the first index that contains a value greater or equal to element. If no such index exists (i.e. all values in the vector are strictly less than element), and the vector length is returned.

Time complexity O(log n).

public fun find_upper_bound(vec: vector<u64>, element: u64): u64
  • @param vec: The vector to be searched.

  • @param element: We check if there is a value higher than it in the vector.

  • @return u64. The index of the member that is larger than element. The length is returned if no member is found.

lt

Checks if a is smaller than b. E.g. x"123" < x"456".

public fun lt(a: vector<u8>, b: vector<u8>): bool
  • @param a: The first operand.

  • @param b: The second operand..

  • @return bool. If a is smaller than b.

Aborts

  • a and b have different lengths.

gt

Checks if a is larger than b. E.g. x"123" < x"456".

public fun gt(a: vector<u8>, b: vector<u8>): bool
  • @param a: The first operand.

  • @param b: The second operand..

  • @return bool. If a is larger than b.

Aborts

  • a and b have different lengths.

lte

Checks if a is smaller or equal to b. E.g. x"123" =< x"456".

public fun lte(a: vector<u8>, b: vector<u8>): bool
  • @param a: The first operand.

  • @param b: The second operand..

  • @return bool. If a is smaller or equal to b.

Aborts

  • a and b have different lengths.

gte

Checks if a is larger or equal to b. E.g. x"123" =< x"456".

public fun gte(a: vector<u8>, b: vector<u8>): bool 
  • @param a: The first operand.

  • @param b: The second operand..

  • @return bool. If a is larger or equal to b.

Aborts

  • a and b have different lengths.

ascending_insertion_sort

Sorts a a in ascending order. E.g. [342] => [234].

public fun ascending_insertion_sort(a: vector<u256>): vector<u256>
  • @param a: The vector to sort.

  • @return vector. Sorted a.

Aborts

  • a and b have different lengths.

descending_insertion_sort

Sorts a a in descending order. E.g. [342] => [432].

public fun descending_insertion_sort(a: vector<u256>): vector<u256>
  • @param a: The vector to sort.

  • @return vector. Sorted a.

Aborts

  • a and b have different lengths.

quick_sort

Sorts a values. E.g. [342] => [234].

This function mutates the original vector.

public fun quick_sort(values: &mut vector<u256>, left: u64, right: u64)
  • @param values: The vector to sort.

  • @param left: The smaller side of the pivot. Pass 0.

  • @param right: The larger side of the pivot. Pass vector::length - 1.

PreviousMerkle ProofNextMath

Last updated 1 year ago

Was this helpful?