vector

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Vector

type Vector[T num.Q] struct {
	// contains filtered or unexported fields
}

数组列表数据结构,默认采用切片slice,使用数组需使用特定的方法

func New

func New[T num.Q]() *Vector[T]

New 空构造

func NewFromSlice

func NewFromSlice[T num.Q](elements []T) *Vector[T]

NewFromSlice 从已有切片构造

func NewFromVector

func NewFromVector[T num.Q](anotherVector *Vector[T], lo, hi int) *Vector[T]

NewFromVector 从已有列表/向量子区间构造

func (*Vector[T]) BinSearch

func (this *Vector[T]) BinSearch(e T, lo, hi int) (rank int)

二分近似查找 在 [lo, hi) 区间查找元素 e,返回不大于e的元素的秩 警告:对空向量无法进行查找,会返回-2

func (*Vector[T]) Clear

func (this *Vector[T]) Clear()

清空向量

func (*Vector[T]) Deduplicate

func (this *Vector[T]) Deduplicate() (removedNumber int)

无序去重,可以保持低秩方向不同元素间的稳定性

func (*Vector[T]) DeepEqual added in v0.0.3

func (this *Vector[T]) DeepEqual(another *Vector[T]) (equal bool)

值判等,以值相等原则进行比较 定义:一个列表在"内容视图"上的相等包括:容量、链表的元素序列 相等,忽略其中的指针

func (*Vector[T]) Disordered

func (this *Vector[T]) Disordered() (disorderedNumber int)

逆序对统计

func (*Vector[T]) Find

func (this *Vector[T]) Find(e T, lo, hi int) (rank int)

无序向量精确区间查找,从后向前精确查找 [lo, hi) 区间内元素的e,返回第一个匹配元素的秩,没有找到就返回-1

func (*Vector[T]) Get

func (this *Vector[T]) Get(r int) (element T, err error)

读取元素 警告:当给出的秩r不在有效范围内时,会返回错误 err

func (*Vector[T]) Insert

func (this *Vector[T]) Insert(r int, element T) (rank int)

插入元素,插入元素 element 到已被占用的秩 r,原向量中自r及其后的元素依次后移一位 警告:不得插入未使用的秩处,尤其是最后一个秩之后的一个位置

func (*Vector[T]) IsEmpty

func (this *Vector[T]) IsEmpty() bool

检查是否为空

func (*Vector[T]) MergeSort

func (this *Vector[T]) MergeSort(lo, hi int)

归并排序,对 [lo, hi) 范围内的元素进行排序 递归版本,通常够用

func (*Vector[T]) PopBack

func (this *Vector[T]) PopBack() (element T)

尾部弹出一个元素 警告:不会检查对象是否为空向量,调用方需自行保证对象不为空

func (*Vector[T]) PushBack

func (this *Vector[T]) PushBack(e T)

尾部压入一个元素

func (*Vector[T]) Put

func (this *Vector[T]) Put(r int, newElement T) (err error)

更改元素 警告:当所给秩r不再有效范围内时,返回错误err

func (*Vector[T]) Remove

func (this *Vector[T]) Remove(lo, hi int) (removedNumber int)

移除区间,并将其后的元素前移补全

func (*Vector[T]) Remove1

func (this *Vector[T]) Remove1(r int) (removedElement T)

移除单个元素,其后元素依次前移补全,返回被移除的元素 警告:不会检查对象是否为空,请调用方自行保证,建议配合 IsEmpty() 控制

func (*Vector[T]) Reverse

func (this *Vector[T]) Reverse()

翻转, 以向量中心点为界,互换对称位置上的元素

func (*Vector[T]) Search

func (this *Vector[T]) Search(e T) (rank int)

有序向量查找 警告:不会检查是否为空向量,请调用方自行检查控制

func (*Vector[T]) Size

func (this *Vector[T]) Size() (usedSize int)

Size 接口,返回已用空间

func (*Vector[T]) String

func (this *Vector[T]) String() string

序列化方法

func (*Vector[T]) ToSlice added in v0.0.3

func (this *Vector[T]) ToSlice() []T

转换为一个新的切片返回

func (*Vector[T]) Traverse

func (this *Vector[T]) Traverse(visit func(element *T))

遍历,使用参数中给定的函数,逐一处理向量中的元素

func (*Vector[T]) Uniquify

func (this *Vector[T]) Uniquify() (deletedNumber int)

有序向量 去重,返回被删除元素的个数

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL