# Vectors

Utility functions for vectors.

## Interface

### <mark style="color:blue;">find\_upper\_bound</mark>

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.

{% hint style="success" %}
Time complexity O(log n).
{% endhint %}

```rust
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.

### <mark style="color:blue;">lt</mark>

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

```rust
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.

### <mark style="color:blue;">gt</mark>

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

```rust
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.

### <mark style="color:blue;">lte</mark>

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

```rust
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.

### <mark style="color:blue;">gte</mark>

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

```rust
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.

### <mark style="color:blue;">ascending\_insertion\_sort</mark>

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

```rust
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.

### <mark style="color:blue;">descending\_insertion\_sort</mark>

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

```rust
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.

### <mark style="color:blue;">quick\_sort</mark>

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

{% hint style="warning" %}
This function mutates the original vector.
{% endhint %}

```rust
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`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.interestprotocol.com/overview/deprecated/sui-tears/utils/vectors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
