X7ROOT File Manager
Current Path:
/opt/golang/1.19.4/test/typeparam
opt
/
golang
/
1.19.4
/
test
/
typeparam
/
📁
..
📄
absdiff.go
(2.95 KB)
📄
absdiff2.go
(3.59 KB)
📄
absdiff3.go
(2.56 KB)
📁
absdiffimp.dir
📄
absdiffimp.go
(187 B)
📁
absdiffimp2.dir
📄
absdiffimp2.go
(187 B)
📄
adder.go
(559 B)
📁
aliasimp.dir
📄
aliasimp.go
(187 B)
📄
append.go
(597 B)
📄
boundmethod.go
(2.74 KB)
📄
builtins.go
(1.92 KB)
📄
chans.go
(8.45 KB)
📁
chansimp.dir
📄
chansimp.go
(187 B)
📄
combine.go
(1.46 KB)
📄
cons.go
(1.98 KB)
📁
dedup.dir
📄
dedup.go
(437 B)
📄
dedup.out
(20 B)
📄
dictionaryCapture-noinline.go
(1.81 KB)
📄
dictionaryCapture.go
(3.26 KB)
📄
dottype.go
(1.36 KB)
📄
dottype.out
(47 B)
📄
double.go
(1.54 KB)
📄
eface.go
(1.12 KB)
📄
equal.go
(1.29 KB)
📄
fact.go
(618 B)
📁
factimp.dir
📄
factimp.go
(187 B)
📁
gencrawler.dir
📄
gencrawler.go
(301 B)
📄
gencrawler.out
(4 B)
📄
genembed.go
(901 B)
📄
genembed2.go
(801 B)
📁
geninline.dir
📄
geninline.go
(187 B)
📄
graph.go
(5.72 KB)
📄
ifaceconv.go
(1.67 KB)
📄
importtest.go
(319 B)
📄
index.go
(1.55 KB)
📄
index2.go
(1.52 KB)
📄
interfacearg.go
(692 B)
📄
issue23536.go
(556 B)
📄
issue376214.go
(401 B)
📄
issue39755.go
(593 B)
📄
issue42758.go
(363 B)
📄
issue44688.go
(1.93 KB)
📄
issue45547.go
(471 B)
📄
issue45722.go
(562 B)
📄
issue45738.go
(290 B)
📄
issue45817.go
(406 B)
📄
issue46461.go
(302 B)
📁
issue46461b.dir
📄
issue46461b.go
(191 B)
📄
issue46472.go
(339 B)
📄
issue46591.go
(347 B)
📄
issue47258.go
(686 B)
📄
issue47272.go
(1.05 KB)
📄
issue47272.out
(29 B)
📄
issue47514.go
(373 B)
📄
issue47514b.go
(336 B)
📁
issue47514c.dir
📄
issue47514c.go
(187 B)
📄
issue47631.go
(832 B)
📄
issue47676.go
(452 B)
📄
issue47684.go
(299 B)
📄
issue47684b.go
(395 B)
📄
issue47684c.go
(317 B)
📄
issue47708.go
(934 B)
📄
issue47710.go
(398 B)
📄
issue47713.go
(888 B)
📄
issue47713.out
(10 B)
📄
issue47716.go
(1.63 KB)
📄
issue47723.go
(350 B)
📄
issue47740.go
(1008 B)
📄
issue47740.out
(0 B)
📄
issue47740b.go
(358 B)
📁
issue47775.dir
📄
issue47775.go
(187 B)
📄
issue47775b.go
(370 B)
📄
issue47797.go
(338 B)
📄
issue47877.go
(444 B)
📄
issue47878.go
(802 B)
📁
issue47892.dir
📄
issue47892.go
(186 B)
📁
issue47892b.dir
📄
issue47892b.go
(191 B)
📄
issue47896.go
(1.44 KB)
📄
issue47901.go
(372 B)
📄
issue47924.go
(296 B)
📄
issue47925.go
(363 B)
📄
issue47925b.go
(486 B)
📄
issue47925c.go
(520 B)
📄
issue47925d.go
(687 B)
📄
issue47929.go
(530 B)
📄
issue47948.go
(272 B)
📄
issue47966.go
(201 B)
📄
issue48013.go
(616 B)
📄
issue48016.go
(574 B)
📄
issue48030.go
(481 B)
📄
issue48042.go
(1.29 KB)
📄
issue48047.go
(427 B)
📄
issue48049.go
(493 B)
📄
issue48056.go
(398 B)
📁
issue48094.dir
📄
issue48094.go
(187 B)
📁
issue48094b.dir
📄
issue48094b.go
(191 B)
📄
issue48137.go
(365 B)
📁
issue48185a.dir
📄
issue48185a.go
(187 B)
📁
issue48185b.dir
📄
issue48185b.go
(187 B)
📄
issue48191.go
(9.73 KB)
📄
issue48198.go
(372 B)
📄
issue48225.go
(610 B)
📄
issue48253.go
(551 B)
📄
issue48276a.go
(337 B)
📄
issue48276a.out
(4 B)
📄
issue48276b.go
(266 B)
📁
issue48280.dir
📄
issue48280.go
(187 B)
📁
issue48306.dir
📄
issue48306.go
(187 B)
📄
issue48317.go
(648 B)
📄
issue48318.go
(581 B)
📁
issue48337a.dir
📄
issue48337a.go
(187 B)
📄
issue48337a.out
(27 B)
📁
issue48337b.dir
📄
issue48337b.go
(187 B)
📄
issue48344.go
(360 B)
📄
issue48424.go
(916 B)
📄
issue48453.go
(393 B)
📁
issue48454.dir
📄
issue48454.go
(187 B)
📁
issue48462.dir
📄
issue48462.go
(187 B)
📄
issue48537.go
(295 B)
📄
issue48538.go
(790 B)
📄
issue48598.go
(475 B)
📄
issue48602.go
(414 B)
📄
issue48604.go
(396 B)
📄
issue48609.go
(291 B)
📄
issue48617.go
(446 B)
📄
issue48645a.go
(510 B)
📄
issue48645a.out
(21 B)
📄
issue48645b.go
(1.45 KB)
📄
issue48711.go
(342 B)
📁
issue48716.dir
📄
issue48716.go
(187 B)
📄
issue48838.go
(467 B)
📁
issue48962.dir
📄
issue48962.go
(194 B)
📁
issue49027.dir
📄
issue49027.go
(187 B)
📄
issue49049.go
(354 B)
📁
issue49241.dir
📄
issue49241.go
(187 B)
📁
issue49246.dir
📄
issue49246.go
(191 B)
📄
issue49295.go
(542 B)
📄
issue49309.go
(351 B)
📄
issue49421.go
(392 B)
📄
issue49432.go
(387 B)
📁
issue49497.dir
📄
issue49497.go
(187 B)
📄
issue49516.go
(423 B)
📁
issue49524.dir
📄
issue49524.go
(187 B)
📁
issue49536.dir
📄
issue49536.go
(191 B)
📄
issue49538.go
(337 B)
📄
issue49547.go
(384 B)
📄
issue49611.go
(211 B)
📁
issue49659.dir
📄
issue49659.go
(191 B)
📄
issue49659b.go
(492 B)
📁
issue49667.dir
📄
issue49667.go
(187 B)
📄
issue49875.go
(256 B)
📁
issue49893.dir
📄
issue49893.go
(191 B)
📄
issue50002.go
(1.27 KB)
📄
issue50109.go
(2.23 KB)
📄
issue50109.out
(13 B)
📄
issue50109b.go
(390 B)
📁
issue50121.dir
📄
issue50121.go
(187 B)
📁
issue50121b.dir
📄
issue50121b.go
(187 B)
📄
issue50147.go
(241 B)
📄
issue50177.go
(2.01 KB)
📄
issue50193.go
(599 B)
📄
issue50193.out
(48 B)
📄
issue50259.go
(244 B)
📄
issue50264.go
(822 B)
📄
issue50317.go
(354 B)
📄
issue50417.go
(1.55 KB)
📄
issue50417b.go
(921 B)
📄
issue50419.go
(689 B)
📁
issue50437.dir
📄
issue50437.go
(191 B)
📁
issue50481b.dir
📄
issue50481b.go
(187 B)
📁
issue50481c.dir
📄
issue50481c.go
(187 B)
📄
issue50481c.out
(2 B)
📁
issue50485.dir
📄
issue50485.go
(191 B)
📁
issue50486.dir
📄
issue50486.go
(191 B)
📁
issue50552.dir
📄
issue50552.go
(191 B)
📁
issue50561.dir
📄
issue50561.go
(191 B)
📁
issue50598.dir
📄
issue50598.go
(187 B)
📄
issue50642.go
(1013 B)
📄
issue50690a.go
(1.64 KB)
📄
issue50690a.out
(20 B)
📄
issue50690b.go
(916 B)
📄
issue50690b.out
(14 B)
📄
issue50690c.go
(917 B)
📄
issue50690c.out
(14 B)
📄
issue50833.go
(415 B)
📁
issue50841.dir
📄
issue50841.go
(191 B)
📄
issue50993.go
(569 B)
📁
issue51219.dir
📄
issue51219.go
(187 B)
📄
issue51219.out
(3 B)
📁
issue51219b.dir
📄
issue51219b.go
(191 B)
📄
issue51232.go
(702 B)
📄
issue51233.go
(663 B)
📄
issue51236.go
(298 B)
📄
issue51245.go
(267 B)
📁
issue51250a.dir
📄
issue51250a.go
(187 B)
📄
issue51303.go
(1.08 KB)
📄
issue51303.out
(40 B)
📄
issue51355.go
(498 B)
📁
issue51367.dir
📄
issue51367.go
(187 B)
📁
issue51423.dir
📄
issue51423.go
(191 B)
📄
issue51521.go
(546 B)
📄
issue51522a.go
(543 B)
📄
issue51522b.go
(730 B)
📄
issue51700.go
(413 B)
📄
issue51733.go
(585 B)
📄
issue51765.go
(308 B)
📄
issue51832.go
(359 B)
📁
issue51836.dir
📄
issue51836.go
(194 B)
📄
issue51840.go
(635 B)
📄
issue51909.go
(591 B)
📄
issue51925.go
(964 B)
📄
issue52026.go
(735 B)
📁
issue52117.dir
📄
issue52117.go
(191 B)
📄
issue52124.go
(257 B)
📄
issue52228.go
(476 B)
📄
issue52241.go
(381 B)
📄
issue53254.go
(304 B)
📄
issue53390.go
(334 B)
📄
issue53406.go
(354 B)
📄
issue53419.go
(419 B)
📄
issue53477.go
(555 B)
📄
issue53762.go
(304 B)
📄
issue54135.go
(478 B)
📄
issue54225.go
(532 B)
📁
issue54302.dir
📄
issue54302.go
(181 B)
📄
list.go
(2.42 KB)
📄
list2.go
(15.26 KB)
📁
listimp.dir
📄
listimp.go
(187 B)
📁
listimp2.dir
📄
listimp2.go
(187 B)
📄
lockable.go
(916 B)
📄
map.go
(885 B)
📁
mapimp.dir
📄
mapimp.go
(187 B)
📄
maps.go
(5.91 KB)
📁
mapsimp.dir
📄
mapsimp.go
(187 B)
📁
mdempsky
📄
metrics.go
(4.45 KB)
📄
min.go
(979 B)
📁
mincheck.dir
📄
mincheck.go
(194 B)
📁
minimp.dir
📄
minimp.go
(187 B)
📁
mutualimp.dir
📄
mutualimp.go
(191 B)
📄
nested.go
(3.01 KB)
📄
nested.out
(155 B)
📄
ordered.go
(2.19 KB)
📄
orderedmap.go
(7.09 KB)
📁
orderedmapsimp.dir
📄
orderedmapsimp.go
(187 B)
📄
pair.go
(739 B)
📁
pairimp.dir
📄
pairimp.go
(187 B)
📄
pragma.go
(411 B)
📁
recoverimp.dir
📄
recoverimp.go
(187 B)
📄
recoverimp.out
(24 B)
📁
select.dir
📄
select.go
(187 B)
📄
sets.go
(5.7 KB)
📁
setsimp.dir
📄
setsimp.go
(187 B)
📄
settable.go
(2.75 KB)
📄
shape1.go
(855 B)
📄
shape1.out
(10 B)
📁
sliceimp.dir
📄
sliceimp.go
(187 B)
📄
slices.go
(7.79 KB)
📄
smallest.go
(825 B)
📄
smoketest.go
(1019 B)
📄
stringable.go
(833 B)
📄
stringer.go
(1.55 KB)
📁
stringerimp.dir
📄
stringerimp.go
(187 B)
📄
struct.go
(783 B)
📁
structinit.dir
📄
structinit.go
(187 B)
📄
subdict.go
(842 B)
📄
sum.go
(923 B)
📄
tparam1.go
(1.06 KB)
📄
typelist.go
(3.23 KB)
📄
typeswitch1.go
(648 B)
📄
typeswitch1.out
(56 B)
📄
typeswitch2.go
(709 B)
📄
typeswitch2.out
(78 B)
📄
typeswitch3.go
(837 B)
📄
typeswitch3.out
(59 B)
📄
typeswitch4.go
(813 B)
📄
typeswitch4.out
(101 B)
📄
typeswitch5.go
(559 B)
📄
typeswitch5.out
(41 B)
📄
typeswitch6.go
(495 B)
📄
typeswitch6.out
(20 B)
📄
typeswitch7.go
(581 B)
📄
typeswitch7.out
(19 B)
📁
valimp.dir
📄
valimp.go
(187 B)
📄
value.go
(1.45 KB)
Editing: orderedmap.go
// run // Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package orderedmap provides an ordered map, implemented as a binary tree. package main import ( "bytes" "context" "fmt" "runtime" ) type Ordered interface { ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string } // _Map is an ordered map. type _Map[K, V any] struct { root *node[K, V] compare func(K, K) int } // node is the type of a node in the binary tree. type node[K, V any] struct { key K val V left, right *node[K, V] } // _New returns a new map. It takes a comparison function that compares two // keys and returns < 0 if the first is less, == 0 if they are equal, // > 0 if the first is greater. func _New[K, V any](compare func(K, K) int) *_Map[K, V] { return &_Map[K, V]{compare: compare} } // _NewOrdered returns a new map whose key is an ordered type. // This is like _New, but does not require providing a compare function. // The map compare function uses the obvious key ordering. func _NewOrdered[K Ordered, V any]() *_Map[K, V] { return _New[K, V](func(k1, k2 K) int { switch { case k1 < k2: return -1 case k1 == k2: return 0 default: return 1 } }) } // find looks up key in the map, returning either a pointer to the slot of the // node holding key, or a pointer to the slot where should a node would go. func (m *_Map[K, V]) find(key K) **node[K, V] { pn := &m.root for *pn != nil { switch cmp := m.compare(key, (*pn).key); { case cmp < 0: pn = &(*pn).left case cmp > 0: pn = &(*pn).right default: return pn } } return pn } // Insert inserts a new key/value into the map. // If the key is already present, the value is replaced. // Reports whether this is a new key. func (m *_Map[K, V]) Insert(key K, val V) bool { pn := m.find(key) if *pn != nil { (*pn).val = val return false } *pn = &node[K, V]{key: key, val: val} return true } // Find returns the value associated with a key, or the zero value // if not present. The found result reports whether the key was found. func (m *_Map[K, V]) Find(key K) (V, bool) { pn := m.find(key) if *pn == nil { var zero V return zero, false } return (*pn).val, true } // keyValue is a pair of key and value used while iterating. type keyValue[K, V any] struct { key K val V } // iterate returns an iterator that traverses the map. func (m *_Map[K, V]) Iterate() *_Iterator[K, V] { sender, receiver := _Ranger[keyValue[K, V]]() var f func(*node[K, V]) bool f = func(n *node[K, V]) bool { if n == nil { return true } // Stop the traversal if Send fails, which means that // nothing is listening to the receiver. return f(n.left) && sender.Send(context.Background(), keyValue[K, V]{n.key, n.val}) && f(n.right) } go func() { f(m.root) sender.Close() }() return &_Iterator[K, V]{receiver} } // _Iterator is used to iterate over the map. type _Iterator[K, V any] struct { r *_Receiver[keyValue[K, V]] } // Next returns the next key and value pair, and a boolean that reports // whether they are valid. If not valid, we have reached the end of the map. func (it *_Iterator[K, V]) Next() (K, V, bool) { keyval, ok := it.r.Next(context.Background()) if !ok { var zerok K var zerov V return zerok, zerov, false } return keyval.key, keyval.val, true } func TestMap() { m := _New[[]byte, int](bytes.Compare) if _, found := m.Find([]byte("a")); found { panic(fmt.Sprintf("unexpectedly found %q in empty map", []byte("a"))) } if !m.Insert([]byte("a"), 'a') { panic(fmt.Sprintf("key %q unexpectedly already present", []byte("a"))) } if !m.Insert([]byte("c"), 'c') { panic(fmt.Sprintf("key %q unexpectedly already present", []byte("c"))) } if !m.Insert([]byte("b"), 'b') { panic(fmt.Sprintf("key %q unexpectedly already present", []byte("b"))) } if m.Insert([]byte("c"), 'x') { panic(fmt.Sprintf("key %q unexpectedly not present", []byte("c"))) } if v, found := m.Find([]byte("a")); !found { panic(fmt.Sprintf("did not find %q", []byte("a"))) } else if v != 'a' { panic(fmt.Sprintf("key %q returned wrong value %c, expected %c", []byte("a"), v, 'a')) } if v, found := m.Find([]byte("c")); !found { panic(fmt.Sprintf("did not find %q", []byte("c"))) } else if v != 'x' { panic(fmt.Sprintf("key %q returned wrong value %c, expected %c", []byte("c"), v, 'x')) } if _, found := m.Find([]byte("d")); found { panic(fmt.Sprintf("unexpectedly found %q", []byte("d"))) } gather := func(it *_Iterator[[]byte, int]) []int { var r []int for { _, v, ok := it.Next() if !ok { return r } r = append(r, v) } } got := gather(m.Iterate()) want := []int{'a', 'b', 'x'} if !_SliceEqual(got, want) { panic(fmt.Sprintf("Iterate returned %v, want %v", got, want)) } } func main() { TestMap() } // _Equal reports whether two slices are equal: the same length and all // elements equal. All floating point NaNs are considered equal. func _SliceEqual[Elem comparable](s1, s2 []Elem) bool { if len(s1) != len(s2) { return false } for i, v1 := range s1 { v2 := s2[i] if v1 != v2 { isNaN := func(f Elem) bool { return f != f } if !isNaN(v1) || !isNaN(v2) { return false } } } return true } // Ranger returns a Sender and a Receiver. The Receiver provides a // Next method to retrieve values. The Sender provides a Send method // to send values and a Close method to stop sending values. The Next // method indicates when the Sender has been closed, and the Send // method indicates when the Receiver has been freed. // // This is a convenient way to exit a goroutine sending values when // the receiver stops reading them. func _Ranger[Elem any]() (*_Sender[Elem], *_Receiver[Elem]) { c := make(chan Elem) d := make(chan struct{}) s := &_Sender[Elem]{ values: c, done: d, } r := &_Receiver[Elem]{ values: c, done: d, } runtime.SetFinalizer(r, (*_Receiver[Elem]).finalize) return s, r } // A _Sender is used to send values to a Receiver. type _Sender[Elem any] struct { values chan<- Elem done <-chan struct{} } // Send sends a value to the receiver. It reports whether the value was sent. // The value will not be sent if the context is closed or the receiver // is freed. func (s *_Sender[Elem]) Send(ctx context.Context, v Elem) bool { select { case <-ctx.Done(): return false case s.values <- v: return true case <-s.done: return false } } // Close tells the receiver that no more values will arrive. // After Close is called, the _Sender may no longer be used. func (s *_Sender[Elem]) Close() { close(s.values) } // A _Receiver receives values from a _Sender. type _Receiver[Elem any] struct { values <-chan Elem done chan<- struct{} } // Next returns the next value from the channel. The bool result indicates // whether the value is valid. func (r *_Receiver[Elem]) Next(ctx context.Context) (v Elem, ok bool) { select { case <-ctx.Done(): case v, ok = <-r.values: } return v, ok } // finalize is a finalizer for the receiver. func (r *_Receiver[Elem]) finalize() { close(r.done) }
Upload File
Create Folder