From 321e34aa928f49012e78ae71e1af0bc0cfb75d28 Mon Sep 17 00:00:00 2001 From: CHEN Feng Date: Sat, 10 Sep 2022 14:37:43 +0800 Subject: [PATCH] fix comments (#100) --- README.md | 14 ++++++++------ README_zh.md | 18 ++++++++++-------- priority_queue.go | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3428725..d2336be 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,14 @@ There are following container interfaces: - `Queue` is a FIFO Queue - `Deque` is a double ended queue +Different interface has different methods. The `Container` interface has following methods: + +- `IsEmpty() bool` Returns whether the container is empty +- `Len() int` returns the number of elements in the container +- `Clear()` to clear the container + +Read [source code](container.go) for details. + Currently container implementations are: - [x] `BuiltinSet` provided a set funtionality based on Go's own `map`. It provides basic operations such as insert, @@ -64,12 +72,6 @@ Currently container implementations are: - [x] `DListQueue` is a bidirectional FIFO queue, implemented based on linked list. - [x] `PriorityQuque` is a priority queue based on heap. Much easier to use and faster than [container/heap](https://pkg.go.dev/container/heap). -Different containers support different methods. The following are the methods supported by all containers: - -- `IsEmpty() bool` Returns whether the container is empty -- `Len() int` returns the number of elements in the container -- `Clear()` to clear the container - ### Iterators Vector, DList and SkipList support iterators. diff --git a/README_zh.md b/README_zh.md index bd04c37..eec975e 100644 --- a/README_zh.md +++ b/README_zh.md @@ -38,10 +38,18 @@ import "github.com/chen3feng/stl4go" - `Queue` 定义了先进先出的队列的接口 - `Deque` 定义了双端队列的接口 +不同的容器接口支持的方法不同,下面是 `Container` 接口的方法: + +- `IsEmpty() bool` 返回容器是否为空 +- `Len() int` 返回容器中的元素个数 +- `Clear()` 清空容器 + +具体请参考[源代码](container.go)。 + 提供的具体容器实现有: -- [x] `BuiltinSet` 集合。基于 Go 自己的 map 封装,提供了插入查找删除等基本操作,以及并集、交集、差集、子集、超集、不交集等高级功能。 -- [x] `Vector` 是基于 slice 封装的向量。提供了中间插入删除、区间删除等功能,依然与 slice 兼容。 +- [x] `BuiltinSet` 是基于 Go 自己的 map 封装的集合。提供了插入查找删除等基本操作,以及并集、交集、差集、子集、超集、不交集等高级功能。 +- [x] `Vector` 是基于切片封装的向量。提供了中间插入删除、区间删除等功能,依然与切片兼容。 - [x] `DList` 是双链表容器,支持两端插入删除。 - [x] `SList` 是单链表容器,支持头部插入删除及尾部插入。 - [x] [跳表(SkipList)](skiplist.md) 是一种有序的关联容器,可以填补 Go `map` 只支持无序的的空白。这是目前全 GitHub 最快的跳表,参见 [skiplist-survey](https://github.com/chen3feng/skiplist-survey)的性能比较 @@ -49,12 +57,6 @@ import "github.com/chen3feng/stl4go" - [x] `DListQueue` 双向进出的队列,基于双链表实现 - [x] `PriorityQuque` 优先队列,基于堆实现,比 [container/heap](https://pkg.go.dev/container/heap) 更易用而且快不少。 -不同的容器支持的方法不同,下面是所有容器都支持的方法: - -- IsEmpty() bool 返回容器是否为空 -- Len() int 返回容器中的元素个数 -- Clear() 清空容器 - ### 迭代器 Vector、DList 和 SkipList 支持迭代器。 diff --git a/priority_queue.go b/priority_queue.go index e656138..3ecee1e 100644 --- a/priority_queue.go +++ b/priority_queue.go @@ -48,7 +48,7 @@ func (pq *PriorityQueue[T]) IsEmpty() bool { return len(pq.heap) == 0 } -// Clear checks whether priority queue has no elements. +// Clear clear the priority queue. func (pq *PriorityQueue[T]) Clear() { pq.heap = pq.heap[0:0] }