crossrealm.gno
0.76 Kb · 42 lines
1// Package crossrealm_f provides a collection realm for testing cross-realm
2// ownership scenarios. It uses a nested structure so that intermediate objects
3// in the ownership chain have RefCount == 1.
4package crossrealm_f
5
6type Entry struct {
7 Key string
8 Value int
9}
10
11var entries []*Entry
12
13func NewEntry(key string, value int) *Entry {
14 return &Entry{Key: key, Value: value}
15}
16
17func Add(cur realm, e *Entry) {
18 entries = append(entries, e)
19}
20
21func Remove(cur realm, key string) *Entry {
22 for i, e := range entries {
23 if e.Key == key {
24 entries = append(entries[:i], entries[i+1:]...)
25 return e
26 }
27 }
28 return nil
29}
30
31func Get(key string) *Entry {
32 for _, e := range entries {
33 if e.Key == key {
34 return e
35 }
36 }
37 return nil
38}
39
40func Len() int {
41 return len(entries)
42}