-2
map [uint64] uint64 값에 대한 내 삽입 및 단축키가 작동하지 않습니다. 누구든지 도와 줄 수 있습니까? 미리 감사드립니다. 가치에 의해지도 "일종의"종류를 갖고 싶습니다.map [int] int 값을 기준으로 정렬하는 방법은 무엇입니까?
자세한 내용은 문의하십시오. 나는이 질문을 개선 할 것이다. 다시 한번 감사드립니다.
package main
import (
"sort"
"fmt"
"time"
"runtime"
"math/rand"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
start := time.Now()
//the map variable
aint := map[uint64]uint64{}
start = time.Now()
for i := uint64(0); i < 100000000; i++ {
aint[i+32132112313] = uint64(rand.Intn(13123123123)+2312423213) //random generation of input data
// aint = insertSort(aint,uint64(rand.Intn(13123123123)))
}
fmt.Printf("%d\n", aint[22])
elapsed := time.Since(start)
fmt.Printf("Entry took %s %d\n", elapsed)
start = time.Now()
quicksort(aint)
// sort.Sort(sort.IntSlice(aint))
elapsed = time.Since(start)
fmt.Printf("Sorting took %s %d\n", elapsed)
}
func insertionsort(items []int) {
var n = len(items)
for i := 1; i < n; i++ {
j := i
for j > 0 {
if items[j-1] > items[j] {
items[j-1], items[j] = items[j], items[j-1]
}
j = j - 1
}
}
}
func quicksort(a map[uint64]uint64) map[uint64]uint64 {
if len(a) < 2 {
return a
}
left, right := uint64(0), uint64(len(a)-1)
pivot := Uint64() % uint64(len(a))
a[pivot], a[right] = a[right], a[pivot]
// does not work anymore from here onwards.
for uint64(i), _ := range a {
if a[i] < a[right] {
a[left], a[i] = a[i], a[left]
left++
}
}
a[left], a[right] = a[right], a[left]
quicksort(a[:left])
quicksort(a[left+1:])
return a
}
빌드되지 않습니다. include [최소, 완전하고 검증 가능한 예제] (https://stackoverflow.com/help/mcve) – Marc
해시 테이블 인 golang 맵은 정의가없는 순서로 표시됩니다. 실제로 보유하고있는 데이터를 정렬 할 수있는 방법이 없습니다. 기껏해야 실제 맵과 키를 포함하는 슬라이스로 구성된 래퍼 유형을 만들고 슬라이스를 정렬 할 수 있습니다. 지도를 반복 할 때 실제로 순서가 지정된 슬라이스를 반복하고 설정된 순서로지도에서 데이터를 검색합니다. 이것은 구현하기가 쉽지 않지만, 여기서 X-Y 문제를 해결하려고하는 것처럼 느낄 수는 없지만 느낄 수는 없습니다. 너 뭐하려고? 아마 더 좋은 방법이있을거야. –