Skip to content

Commit

Permalink
fix comments (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
chen3feng authored Sep 10, 2022
1 parent 3f11312 commit 321e34a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
18 changes: 10 additions & 8 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,25 @@ 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)的性能比较
- [x] `Stack`,栈基于 Slice 实现
- [x] `DListQueue` 双向进出的队列,基于双链表实现
- [x] `PriorityQuque` 优先队列,基于堆实现,比 [container/heap](https://pkg.go.dev/container/heap) 更易用而且快不少。

不同的容器支持的方法不同,下面是所有容器都支持的方法:

- IsEmpty() bool 返回容器是否为空
- Len() int 返回容器中的元素个数
- Clear() 清空容器

### 迭代器

Vector、DList 和 SkipList 支持迭代器。
Expand Down
2 changes: 1 addition & 1 deletion priority_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down

0 comments on commit 321e34a

Please sign in to comment.