mytype

package
v0.0.0-...-f874258 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2023 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const BucketsCount = 100

桶的格子数

Variables

This section is empty.

Functions

func GetBucketKey

func GetBucketKey(key string) int

自定义hash算法获取key

Types

type ArrayList

type ArrayList struct {
	DataStore []interface{}
	TheSize   int
}

数据结构

func NewArrayList

func NewArrayList() *ArrayList

新建

func (*ArrayList) Append

func (list *ArrayList) Append(val ...interface{})

追加数据

func (*ArrayList) Clear

func (list *ArrayList) Clear()

清空

  1. To remove all elements, simply set the slice to nil. a := []string{"A", "B", "C", "D", "E"} a = nil fmt.Println(a, len(a), cap(a)) // [] 0 0

  2. Keep allocated memory . To keep the underlying array, slice the slice to zero length. a := []string{"A", "B", "C", "D", "E"} a = a[:0] fmt.Println(a, len(a), cap(a)) // [] 0 5 If the slice is extended again, the original data reappears. fmt.Println(a[:2]) // [A B]

func (*ArrayList) Delete

func (list *ArrayList) Delete(index int) error

删除元素

func (*ArrayList) Get

func (list *ArrayList) Get(index int) (interface{}, error)

获取数据

func (*ArrayList) Insert

func (list *ArrayList) Insert(index int, val interface{}) error

func (*ArrayList) Set

func (list *ArrayList) Set(index int, newValue interface{}) error

重置元素

func (*ArrayList) Size

func (list *ArrayList) Size() int

返回长度

func (*ArrayList) String

func (list *ArrayList) String() string

字符打印

type HashMap

type HashMap struct {
	Buckets [BucketsCount]*Node //存在node节点的数组
}

hashMap 桶

func NewHashMap

func NewHashMap() HashMap

新建一个hashMap桶

func (*HashMap) Get

func (h *HashMap) Get(key string) interface{}

从hashMap中获取某个key的值

func (*HashMap) Put

func (h *HashMap) Put(data Value)

在hashMap桶中新加一个节点

type List

type List interface {
	Size() int
	Get(index int) (interface{}, error)
	Set(index int, newValue interface{}) error
	Insert(index int, val interface{}) error
	Append(val ...interface{})
	Delete(index int) error
	String() string
	Clear()
}

接口

type Node

type Node struct {
	Next *Node
	Data Value
}

node节点

func NewEmptyNode

func NewEmptyNode() *Node

创建一个空node

type Value

type Value struct {
	Key   string
	Value interface{}
}

node节点存放的实际对象

Jump to

Keyboard shortcuts

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