1
2
3
4
5 package ssa
6
7 import (
8 "cmd/internal/src"
9 "math"
10 )
11
12
13
14
15
16
17 type biasedSparseMap struct {
18 s *sparseMap
19 first int
20 }
21
22
23 func newBiasedSparseMap(first, last int) *biasedSparseMap {
24 if first > last {
25 return &biasedSparseMap{first: math.MaxInt32, s: nil}
26 }
27 return &biasedSparseMap{first: first, s: newSparseMap(1 + last - first)}
28 }
29
30
31 func (s *biasedSparseMap) cap() int {
32 if s == nil || s.s == nil {
33 return 0
34 }
35 return s.s.cap() + int(s.first)
36 }
37
38
39 func (s *biasedSparseMap) size() int {
40 if s == nil || s.s == nil {
41 return 0
42 }
43 return s.s.size()
44 }
45
46
47 func (s *biasedSparseMap) contains(x uint) bool {
48 if s == nil || s.s == nil {
49 return false
50 }
51 if int(x) < s.first {
52 return false
53 }
54 if int(x) >= s.cap() {
55 return false
56 }
57 return s.s.contains(ID(int(x) - s.first))
58 }
59
60
61
62 func (s *biasedSparseMap) get(x uint) int32 {
63 if s == nil || s.s == nil {
64 return -1
65 }
66 if int(x) < s.first {
67 return -1
68 }
69 if int(x) >= s.cap() {
70 return -1
71 }
72 return s.s.get(ID(int(x) - s.first))
73 }
74
75
76
77 func (s *biasedSparseMap) getEntry(i int) (x uint, v int32) {
78 e := s.s.contents()[i]
79 x = uint(int(e.key) + s.first)
80 v = e.val
81 return
82 }
83
84
85 func (s *biasedSparseMap) add(x uint) {
86 if int(x) < s.first || int(x) >= s.cap() {
87 return
88 }
89 s.s.set(ID(int(x)-s.first), 0, src.NoXPos)
90 }
91
92
93 func (s *biasedSparseMap) set(x uint, v int32) {
94 if int(x) < s.first || int(x) >= s.cap() {
95 return
96 }
97 s.s.set(ID(int(x)-s.first), v, src.NoXPos)
98 }
99
100
101 func (s *biasedSparseMap) remove(x uint) {
102 if int(x) < s.first || int(x) >= s.cap() {
103 return
104 }
105 s.s.remove(ID(int(x) - s.first))
106 }
107
108 func (s *biasedSparseMap) clear() {
109 if s.s != nil {
110 s.s.clear()
111 }
112 }
113
View as plain text