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: graph.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 main import ( "errors" "fmt" ) // _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 } // A Graph is a collection of nodes. A node may have an arbitrary number // of edges. An edge connects two nodes. Both nodes and edges must be // comparable. This is an undirected simple graph. type _Graph[_Node _NodeC[_Edge], _Edge _EdgeC[_Node]] struct { nodes []_Node } // _NodeC is the contraints on a node in a graph, given the _Edge type. type _NodeC[_Edge any] interface { comparable Edges() []_Edge } // Edgec is the constraints on an edge in a graph, given the _Node type. type _EdgeC[_Node any] interface { comparable Nodes() (a, b _Node) } // _New creates a new _Graph from a collection of Nodes. func _New[_Node _NodeC[_Edge], _Edge _EdgeC[_Node]](nodes []_Node) *_Graph[_Node, _Edge] { return &_Graph[_Node, _Edge]{nodes: nodes} } // nodePath holds the path to a node during ShortestPath. // This should ideally be a type defined inside ShortestPath, // but the translator tool doesn't support that. type nodePath[_Node _NodeC[_Edge], _Edge _EdgeC[_Node]] struct { node _Node path []_Edge } // ShortestPath returns the shortest path between two nodes, // as an ordered list of edges. If there are multiple shortest paths, // which one is returned is unpredictable. func (g *_Graph[_Node, _Edge]) ShortestPath(from, to _Node) ([]_Edge, error) { visited := make(map[_Node]bool) visited[from] = true workqueue := []nodePath[_Node, _Edge]{nodePath[_Node, _Edge]{from, nil}} for len(workqueue) > 0 { current := workqueue workqueue = nil for _, np := range current { edges := np.node.Edges() for _, edge := range edges { a, b := edge.Nodes() if a == np.node { a = b } if !visited[a] { ve := append([]_Edge(nil), np.path...) ve = append(ve, edge) if a == to { return ve, nil } workqueue = append(workqueue, nodePath[_Node, _Edge]{a, ve}) visited[a] = true } } } } return nil, errors.New("no path") } type direction int const ( north direction = iota ne east se south sw west nw up down ) func (dir direction) String() string { strs := map[direction]string{ north: "north", ne: "ne", east: "east", se: "se", south: "south", sw: "sw", west: "west", nw: "nw", up: "up", down: "down", } if str, ok := strs[dir]; ok { return str } return fmt.Sprintf("direction %d", dir) } type mazeRoom struct { index int exits [10]int } type mazeEdge struct { from, to int dir direction } // Edges returns the exits from the room. func (m mazeRoom) Edges() []mazeEdge { var r []mazeEdge for i, exit := range m.exits { if exit != 0 { r = append(r, mazeEdge{ from: m.index, to: exit, dir: direction(i), }) } } return r } // Nodes returns the rooms connected by an edge. //go:noinline func (e mazeEdge) Nodes() (mazeRoom, mazeRoom) { m1, ok := zork[e.from] if !ok { panic("bad edge") } m2, ok := zork[e.to] if !ok { panic("bad edge") } return m1, m2 } // The first maze in Zork. Room indexes based on original Fortran data file. // You are in a maze of twisty little passages, all alike. var zork = map[int]mazeRoom{ 11: {exits: [10]int{north: 11, south: 12, east: 14}}, // west to Troll Room 12: {exits: [10]int{south: 11, north: 14, east: 13}}, 13: {exits: [10]int{west: 12, north: 14, up: 16}}, 14: {exits: [10]int{west: 13, north: 11, east: 15}}, 15: {exits: [10]int{south: 14}}, // Dead End 16: {exits: [10]int{east: 17, north: 13, sw: 18}}, // skeleton, etc. 17: {exits: [10]int{west: 16}}, // Dead End 18: {exits: [10]int{down: 16, east: 19, west: 18, up: 22}}, 19: {exits: [10]int{up: 29, west: 18, ne: 15, east: 20, south: 30}}, 20: {exits: [10]int{ne: 19, west: 20, se: 21}}, 21: {exits: [10]int{north: 20}}, // Dead End 22: {exits: [10]int{north: 18, east: 24, down: 23, south: 28, west: 26, nw: 22}}, 23: {exits: [10]int{east: 22, west: 28, up: 24}}, 24: {exits: [10]int{ne: 25, down: 23, nw: 28, sw: 26}}, 25: {exits: [10]int{sw: 24}}, // Grating room (up to Clearing) 26: {exits: [10]int{west: 16, sw: 24, east: 28, up: 22, north: 27}}, 27: {exits: [10]int{south: 26}}, // Dead End 28: {exits: [10]int{east: 22, down: 26, south: 23, west: 24}}, 29: {exits: [10]int{west: 30, nw: 29, ne: 19, south: 19}}, 30: {exits: [10]int{west: 29, south: 19}}, // ne to Cyclops Room } func TestShortestPath() { // The Zork maze is not a proper undirected simple graph, // as there are some one way paths (e.g., 19 -> 15), // but for this test that doesn't matter. // Set the index field in the map. Simpler than doing it in the // composite literal. for k := range zork { r := zork[k] r.index = k zork[k] = r } var nodes []mazeRoom for idx, room := range zork { mridx := room mridx.index = idx nodes = append(nodes, mridx) } g := _New[mazeRoom, mazeEdge](nodes) path, err := g.ShortestPath(zork[11], zork[30]) if err != nil { panic(fmt.Sprintf("%v", err)) } var steps []direction for _, edge := range path { steps = append(steps, edge.dir) } want := []direction{east, west, up, sw, east, south} if !_SliceEqual(steps, want) { panic(fmt.Sprintf("ShortestPath returned %v, want %v", steps, want)) } } func main() { TestShortestPath() }
Upload File
Create Folder