샘플
golang.org/x/sync v0.22.0: syncmap.Map
검증된 샘플 — golang golang.org/x/sync v0.22.0: syncmap.Map. go 1.26 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: syncmap.Map Store stores key-value pair…
sha256:790af6712925de14871c37b6dff75594fa6d129fee8ec89b8da639a4bd86fc09
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 go
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f… |
2026-08-27 |
케이스
HOW- 목표
- verify golang.org/x/sync/syncmap.Map in pkg:golang/golang.org/x/sync@v0.22.0
- 심벌
-
- golang.org/x/sync/syncmap.Map
- 생성일
- 2026-08-27T22:02:28Z
컨트랙트
- syncmap.Map Store stores key-value pair and Load retrieves it
- syncmap.Map Load on nonexistent key returns ok=false
- syncmap.Map LoadOrStore returns existing value if present without modifying
- syncmap.Map LoadOrStore stores and returns new value when key is absent
- syncmap.Map LoadAndDelete deletes key and returns previous value and loaded=true
- syncmap.Map Delete removes key from map
- syncmap.Map Swap replaces value and returns previous value
- syncmap.Map CompareAndSwap conditionally replaces value when old matches
- syncmap.Map CompareAndDelete conditionally deletes key when old matches
- syncmap.Map Range iterates over entries and stops when callback returns false
- syncmap.Map safely handles concurrent reads and writes from multiple goroutines
파일
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
소스
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify golang.org/x/sync/syncmap.Map in pkg:golang/golang.org/x/sync@v0.22.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/sync@v0.22.0
Demonstrate these symbols/APIs:
- golang.org/x/sync/syncmap.Map
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:bfe72d6d8164687b2e49dea302c46696ee259baf497617b8aeaa93c283fb0385","contract":["syncmap.Map Store stores key-value pair and Load retrieves it","syncmap.Map Load on nonexistent key returns ok=false","syncmap.Map LoadOrStore returns existing value if present without modifying","syncmap.Map LoadOrStore stores and returns new value when key is absent","syncmap.Map LoadAndDelete deletes key and returns previous value and loaded=true","syncmap.Map Delete removes key from map","syncmap.Map Swap replaces value and returns previous value","syncmap.Map CompareAndSwap conditionally replaces value when old matches","syncmap.Map CompareAndDelete conditionally deletes key when old matches","syncmap.Map Range iterates over entries and stops when callback returns false","syncmap.Map safely handles concurrent reads and writes from multiple goroutines"],"goal":"verify golang.org/x/sync/syncmap.Map in pkg:golang/golang.org/x/sync@v0.22.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sync@v0.22.0"],"schemaVersion":1,"symbols":["golang.org/x/sync/syncmap.Map"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/sync@v0.22.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sync@v0.22.0","symbols":["golang.org/x/sync/syncmap.Map"],"verifierAdapter":"golang@1"}
module sample
go 1.25.0
require golang.org/x/sync v0.22.0
golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek=
golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
package main
import (
"fmt"
"golang.org/x/sync/syncmap"
)
func main() {
var m syncmap.Map
m.Store("greeting", "hello world")
if val, ok := m.Load("greeting"); ok {
fmt.Println(val)
}
}
{
"schemaVersion": 1,
"goal": "verify golang.org/x/sync/syncmap.Map in pkg:golang/golang.org/x/sync@v0.22.0",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/sync@v0.22.0"
],
"symbols": [
"golang.org/x/sync/syncmap.Map"
]
}
package main
import (
"fmt"
"sync"
"golang.org/x/sync/syncmap"
)
func assert(cond bool, msg string) {
if !cond {
panic("assertion failed: " + msg)
}
}
func main() {
// Test 1: Store and Load
{
var m syncmap.Map
m.Store("key1", "val1")
val, ok := m.Load("key1")
assert(ok && val == "val1", "Store and Load should return stored value")
_, ok = m.Load("nonexistent")
assert(!ok, "Load on nonexistent key should return ok=false")
}
// Test 2: LoadOrStore
{
var m syncmap.Map
actual, loaded := m.LoadOrStore("key1", "val1")
assert(!loaded && actual == "val1", "LoadOrStore should insert new entry when key is missing")
actual, loaded = m.LoadOrStore("key1", "val2")
assert(loaded && actual == "val1", "LoadOrStore should return existing entry without modifying")
}
// Test 3: LoadAndDelete and Delete
{
var m syncmap.Map
m.Store("key1", "val1")
val, loaded := m.LoadAndDelete("key1")
assert(loaded && val == "val1", "LoadAndDelete should return previous value and loaded=true")
_, loaded = m.LoadAndDelete("key1")
assert(!loaded, "LoadAndDelete on missing key should return loaded=false")
m.Store("key2", "val2")
m.Delete("key2")
_, ok := m.Load("key2")
assert(!ok, "Delete should remove entry")
}
// Test 4: Swap
{
var m syncmap.Map
prev, loaded := m.Swap("key1", "val1")
assert(!loaded && prev == nil, "Swap on new key should return loaded=false and prev=nil")
prev, loaded = m.Swap("key1", "val2")
assert(loaded && prev == "val1", "Swap on existing key should return previous value")
val, ok := m.Load("key1")
assert(ok && val == "val2", "Load should reflect swapped value")
}
// Test 5: CompareAndSwap
{
var m syncmap.Map
m.Store("key1", "val1")
swapped := m.CompareAndSwap("key1", "wrong", "val2")
assert(!swapped, "CompareAndSwap with mismatched old value should return false")
val, ok := m.Load("key1")
assert(ok && val == "val1", "CompareAndSwap failure should leave value untouched")
swapped = m.CompareAndSwap("key1", "val1", "val2")
assert(swapped, "CompareAndSwap with matching old value should return true")
val, ok = m.Load("key1")
assert(ok && val == "val2", "CompareAndSwap success should update value")
}
// Test 6: CompareAndDelete
{
var m syncmap.Map
m.Store("key1", "val1")
deleted := m.CompareAndDelete("key1", "wrong")
assert(!deleted, "CompareAndDelete with mismatched old value should return false")
val, ok := m.Load("key1")
assert(ok && val == "val1", "CompareAndDelete failure should leave key intact")
deleted = m.CompareAndDelete("key1", "val1")
assert(deleted, "CompareAndDelete with matching old value should return true")
_, ok = m.Load("key1")
assert(!ok, "CompareAndDelete success should remove key")
}
// Test 7: Range
{
var m syncmap.Map
m.Store("k1", 1)
m.Store("k2", 2)
m.Store("k3", 3)
visited := make(map[string]int)
m.Range(func(k, v any) bool {
visited[k.(string)] = v.(int)
return true
})
assert(len(visited) == 3 && visited["k1"] == 1 && visited["k2"] == 2 && visited["k3"] == 3, "Range should visit all entries")
count := 0
m.Range(func(k, v any) bool {
count++
return false // stop early
})
assert(count == 1, "Range should stop when false is returned")
}
// Test 8: Concurrent read/write safety
{
var m syncmap.Map
var wg sync.WaitGroup
const numGoroutines = 50
const iters = 100
for i := 0; i < numGoroutines; i++ {
wg.Add(1)
go func(gid int) {
defer wg.Done()
for j := 0; j < iters; j++ {
key := fmt.Sprintf("k-%d", (gid+j)%10)
m.Store(key, j)
m.Load(key)
m.LoadOrStore(key, j)
if j%2 == 0 {
m.Delete(key)
}
}
}(i)
}
wg.Wait()
}
fmt.Println("Contract verification passed successfully")
}
오리진 시더
익명