mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-15 21:20:58 +00:00
Re-translate the Japanese version (#1871)
* Retranslate Japanese docs with GPT-5.4 * Retranslate Japanese code with GPT-5.4
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
// File: vertex.go
|
||||
// Created Time: 2023-02-18
|
||||
// Author: Reanon (793584285@qq.com)
|
||||
|
||||
package pkg
|
||||
|
||||
// Vertex は頂点クラス
|
||||
type Vertex struct {
|
||||
Val int
|
||||
}
|
||||
|
||||
// NewVertex は頂点のコンストラクタ
|
||||
func NewVertex(val int) Vertex {
|
||||
return Vertex{
|
||||
Val: val,
|
||||
}
|
||||
}
|
||||
|
||||
// ValsToVets は値リストを頂点リストにデシリアライズする
|
||||
func ValsToVets(vals []int) []Vertex {
|
||||
vets := make([]Vertex, len(vals))
|
||||
for i := 0; i < len(vals); i++ {
|
||||
vets[i] = NewVertex(vals[i])
|
||||
}
|
||||
return vets
|
||||
}
|
||||
|
||||
// VetsToVals は頂点リストを値リストにシリアライズする
|
||||
func VetsToVals(vets []Vertex) []int {
|
||||
vals := make([]int, len(vets))
|
||||
for i := range vets {
|
||||
vals[i] = vets[i].Val
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
// DeleteSliceElms はスライスの指定要素を削除する
|
||||
func DeleteSliceElms[T any](a []T, elms ...T) []T {
|
||||
if len(a) == 0 || len(elms) == 0 {
|
||||
return a
|
||||
}
|
||||
// まず要素を set に変換する
|
||||
m := make(map[any]struct{})
|
||||
for _, v := range elms {
|
||||
m[v] = struct{}{}
|
||||
}
|
||||
// 指定した要素を除外する
|
||||
res := make([]T, 0, len(a))
|
||||
for _, v := range a {
|
||||
if _, ok := m[v]; !ok {
|
||||
res = append(res, v)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user