Module std::vec

Vec utility functions.

Pure Hew implementations for common vector operations. These replace the equivalent Rust FFI functions for simple linear scans.

Contents

Functions

Function index_of_i32

pub fn index_of_i32(v: Vec<i32>, val: i32) -> Option<i64>

Return Some of the index of val in a Vec<i32>, or None if not found.

Function index_of_i64

pub fn index_of_i64(v: Vec<i64>, val: i64) -> Option<i64>

Return Some of the index of val in a Vec<i64>, or None if not found.

Function index_of_f64

pub fn index_of_f64(v: Vec<f64>, val: f64) -> Option<i64>

Return Some of the index of the first occurrence of val in v, or None if not found. Uses exact equality; NaN will never match.

Examples

import std.vec;

fn main() {
    var v: Vec<f64> = Vec.new();
    v.push(1.5);
    v.push(2.5);
    match vec.index_of_f64(v, 2.5) {
        .Some(i) => println(i),  // 1
        .None => println("not found"),
    }
    match vec.index_of_f64(v, 9.9) {
        .Some(i) => println(i),
        .None => println("not found"),  // not found
    }
}

Function index_of_str

pub fn index_of_str(v: Vec<string>, val: string) -> Option<i64>

Return Some of the index of the first occurrence of val in v, or None if not found.

Examples

import std.vec;

fn main() {
    var v: Vec<string> = Vec.new();
    v.push("a");
    v.push("b");
    match vec.index_of_str(v, "b") {
        .Some(i) => println(i),  // 1
        .None => println("not found"),
    }
    match vec.index_of_str(v, "z") {
        .Some(i) => println(i),
        .None => println("not found"),  // not found
    }
}

Function first_i64

pub fn first_i64(v: Vec<i64>) -> Option<i64>

Return Some of the first element of a Vec<i64>, or None if empty.

Function first_f64

pub fn first_f64(v: Vec<f64>) -> Option<f64>

Return Some of the first element of v, or None if v is empty.

Function first_str

pub fn first_str(v: Vec<string>) -> Option<string>

Return Some of the first element of v, or None if v is empty.

Function last_i64

pub fn last_i64(v: Vec<i64>) -> Option<i64>

Return Some of the last element of a Vec<i64>, or None if empty.

Function last_f64

pub fn last_f64(v: Vec<f64>) -> Option<f64>

Return Some of the last element of v, or None if v is empty.

Function last_str

pub fn last_str(v: Vec<string>) -> Option<string>

Return Some of the last element of v, or None if v is empty.

Function min_i32

pub fn min_i32(v: Vec<i32>) -> Option<i64>

Return Some of the smallest element in a Vec<i32>, or None if empty.

Function min_i64

pub fn min_i64(v: Vec<i64>) -> Option<i64>

Return Some of the smallest element in a Vec<i64>, or None if empty.

Function min_f64

pub fn min_f64(v: Vec<f64>) -> Option<f64>

Return Some of the smallest element in v, or None if v is empty. NaN propagates: if any element is NaN the result is unspecified.

Function max_i32

pub fn max_i32(v: Vec<i32>) -> Option<i64>

Return Some of the largest element in a Vec<i32>, or None if empty.

Function max_i64

pub fn max_i64(v: Vec<i64>) -> Option<i64>

Return Some of the largest element in a Vec<i64>, or None if empty.

Function max_f64

pub fn max_f64(v: Vec<f64>) -> Option<f64>

Return Some of the largest element in v, or None if v is empty. NaN propagates: if any element is NaN the result is unspecified.