We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 348dade commit d0b7a8fCopy full SHA for d0b7a8f
src/essential/senior/90.generic.md
@@ -1,7 +1,6 @@
1
---
2
date: 2022-08-26
3
4
-
5
# 泛型
6
7
泛型,或者更学术化的名称 —— 参数化多态(Parameterized
@@ -250,10 +249,6 @@ func Assert[T any](v any) (bool, T) {
250
249
}
251
```
252
253
254
255
256
257
## 类型集
258
259
在 1.18 以后,接口的定义变为了类型集 `(type set)`,含有类型集的接口又称为 `General interfaces` 即通用接口。
@@ -724,6 +719,14 @@ func (heap *BinaryHeap[T]) down(i int) {
724
719
func (heap *BinaryHeap[T]) Size() int {
725
720
return len(heap.s)
726
721
722
+
723
+func NewHeap[T any](n int, c Comparator[T]) BinaryHeap[T] {
+ var heap BinaryHeap[T]
+ heap.s = make([]T, 0, n)
+ heap.Comparator = c
727
+ return heap
728
+}
729
730
731
732
使用起来如下
0 commit comments