XU XUv0.8.8
中文

API

#container/heap

import: #container/heap

counts: 6 fns, 6 methods, 2 types, 0 consts, 0 ifaces

IntHeap / StrHeap min-heaps.

struct IntHeap

XuAPI
pub struct IntHeap {
    pub a []int
    pub n int
}

Purpose

Binary min-heap aligned with `container/heap` Init/Push/Pop, specialized to `IntHeap` / `StrHeap` (no Interface / function values). Logical length `n` is separate from backing capacity so Pop is O(log n) and does not rebuild the array. Mutating API is methods (field `.push` on `&mut Struct` params does not write the descriptor back).

Parameters

a []int
field ([]int)
n int
count, length, or limit

struct StrHeap

XuAPI
pub struct StrHeap {
    pub a []string
    pub n int
}

Purpose

Public struct `StrHeap`.

Parameters

a []string
field ([]string)
n int
count, length, or limit

new_ints

XuAPI
pub fn new_ints() IntHeap

Purpose

Construct ints.

Parameters

none

Returns

IntHeap — a value of this type

new_strs

XuAPI
pub fn new_strs() StrHeap

Purpose

Construct strs.

Parameters

none

Returns

StrHeap — a value of this type

from_ints

XuAPI
pub fn from_ints(xs []int) IntHeap

Purpose

Build from ints.

Parameters

xs []int
slice to operate on ([]int)

Returns

IntHeap — a value of this type

from_strs

XuAPI
pub fn from_strs(xs []string) StrHeap

Purpose

Build from strs.

Parameters

xs []string
slice to operate on ([]string)

Returns

StrHeap — a value of this type

len_ints

XuAPI
pub fn len_ints(h &IntHeap) int

Purpose

Len int slice.

Parameters

h &IntHeap
height or handle (borrowed; caller keeps it; type &IntHeap)

Returns

int — a value of this type

len_strs

XuAPI
pub fn len_strs(h &StrHeap) int

Purpose

Len strs.

Parameters

h &StrHeap
height or handle (borrowed; caller keeps it; type &StrHeap)

Returns

int — a value of this type

(&mut StrHeap) init

XuAPI
pub fn (h &mut StrHeap) init()

Purpose

Call `init` on `&mut StrHeap`.

Parameters

h &mut StrHeap
receiver &mut StrHeap (exclusive borrow)

(&mut IntHeap) init

XuAPI
pub fn (h &mut IntHeap) init()

Purpose

Call `init` on `&mut IntHeap`.

Parameters

h &mut IntHeap
receiver &mut IntHeap (exclusive borrow)

(&mut IntHeap) push

XuAPI
pub fn (h &mut IntHeap) push(x int)

Purpose

Call `push` on `&mut IntHeap`.

Parameters

h &mut IntHeap
receiver &mut IntHeap (exclusive borrow)
x int
value (int)

(&mut IntHeap) pop

XuAPI
pub fn (h &mut IntHeap) pop() int

Purpose

Call `pop` on `&mut IntHeap`. Throws on failure.

Parameters

h &mut IntHeap
receiver &mut IntHeap (exclusive borrow)

Returns

int — a value of this type

(&mut StrHeap) push

XuAPI
pub fn (h &mut StrHeap) push(x string)

Purpose

Call `push` on `&mut StrHeap`.

Parameters

h &mut StrHeap
receiver &mut StrHeap (exclusive borrow)
x string
value (string)

(&mut StrHeap) pop

XuAPI
pub fn (h &mut StrHeap) pop() string

Purpose

Call `pop` on `&mut StrHeap`. Throws on failure.

Parameters

h &mut StrHeap
receiver &mut StrHeap (exclusive borrow)

Returns

string — result string