| |
| |
| |
|
|
| package ssa |
|
|
| import ( |
| "math" |
| ) |
|
|
| |
| |
| |
| |
| |
| type biasedSparseMap struct { |
| s *sparseMap |
| first int |
| } |
|
|
| |
| func newBiasedSparseMap(first, last int) *biasedSparseMap { |
| if first > last { |
| return &biasedSparseMap{first: math.MaxInt32, s: nil} |
| } |
| return &biasedSparseMap{first: first, s: newSparseMap(1 + last - first)} |
| } |
|
|
| |
| func (s *biasedSparseMap) cap() int { |
| if s == nil || s.s == nil { |
| return 0 |
| } |
| return s.s.cap() + s.first |
| } |
|
|
| |
| func (s *biasedSparseMap) size() int { |
| if s == nil || s.s == nil { |
| return 0 |
| } |
| return s.s.size() |
| } |
|
|
| |
| func (s *biasedSparseMap) contains(x uint) bool { |
| if s == nil || s.s == nil { |
| return false |
| } |
| if int(x) < s.first { |
| return false |
| } |
| if int(x) >= s.cap() { |
| return false |
| } |
| return s.s.contains(ID(int(x) - s.first)) |
| } |
|
|
| |
| |
| func (s *biasedSparseMap) get(x uint) (int32, bool) { |
| if s == nil || s.s == nil { |
| return 0, false |
| } |
| if int(x) < s.first { |
| return 0, false |
| } |
| if int(x) >= s.cap() { |
| return 0, false |
| } |
| k := ID(int(x) - s.first) |
| if !s.s.contains(k) { |
| return 0, false |
| } |
| return s.s.get(k) |
| } |
|
|
| |
| |
| func (s *biasedSparseMap) getEntry(i int) (x uint, v int32) { |
| e := s.s.contents()[i] |
| x = uint(int(e.key) + s.first) |
| v = e.val |
| return |
| } |
|
|
| |
| func (s *biasedSparseMap) set(x uint, v int32) { |
| if int(x) < s.first || int(x) >= s.cap() { |
| return |
| } |
| s.s.set(ID(int(x)-s.first), v) |
| } |
|
|
| |
| func (s *biasedSparseMap) remove(x uint) { |
| if int(x) < s.first || int(x) >= s.cap() { |
| return |
| } |
| s.s.remove(ID(int(x) - s.first)) |
| } |
|
|
| func (s *biasedSparseMap) clear() { |
| if s.s != nil { |
| s.s.clear() |
| } |
| } |
|
|