(ids common.Pgids)
| 171 | } |
| 172 | |
| 173 | func (f *hashMap) mergeSpans(ids common.Pgids) { |
| 174 | if len(ids) == 0 { |
| 175 | return |
| 176 | } |
| 177 | sort.Sort(ids) |
| 178 | |
| 179 | common.Verify(func() { |
| 180 | ids1Freemap := f.idsFromFreemaps() |
| 181 | ids2Forward := f.idsFromForwardMap() |
| 182 | ids3Backward := f.idsFromBackwardMap() |
| 183 | |
| 184 | if !reflect.DeepEqual(ids1Freemap, ids2Forward) { |
| 185 | panic(fmt.Sprintf("Detected mismatch, f.freemaps: %v, f.forwardMap: %v", f.freemaps, f.forwardMap)) |
| 186 | } |
| 187 | if !reflect.DeepEqual(ids1Freemap, ids3Backward) { |
| 188 | panic(fmt.Sprintf("Detected mismatch, f.freemaps: %v, f.backwardMap: %v", f.freemaps, f.backwardMap)) |
| 189 | } |
| 190 | |
| 191 | prev := common.Pgid(0) |
| 192 | for _, id := range ids { |
| 193 | // The ids shouldn't have duplicated free ID. |
| 194 | if prev == id { |
| 195 | panic(fmt.Sprintf("detected duplicated free ID: %d in ids: %v", id, ids)) |
| 196 | } |
| 197 | prev = id |
| 198 | |
| 199 | // The ids shouldn't have any overlap with the existing f.freemaps. |
| 200 | if _, ok := ids1Freemap[id]; ok { |
| 201 | panic(fmt.Sprintf("detected overlapped free page ID: %d between ids: %v and existing f.freemaps: %v", id, ids, f.freemaps)) |
| 202 | } |
| 203 | } |
| 204 | }) |
| 205 | |
| 206 | start := ids[0] |
| 207 | end := ids[0] |
| 208 | for i := 1; i < len(ids); i++ { |
| 209 | id := ids[i] |
| 210 | if id == end+1 { |
| 211 | end = id |
| 212 | continue |
| 213 | } |
| 214 | |
| 215 | f.mergeWithExistingSpan(start, end) |
| 216 | start, end = id, id |
| 217 | } |
| 218 | f.mergeWithExistingSpan(start, end) |
| 219 | } |
| 220 | |
| 221 | // mergeWithExistingSpan merges free span [start, end] with adjacent existing free spans (both backward and forward). |
| 222 | func (f *hashMap) mergeWithExistingSpan(start, end common.Pgid) { |
nothing calls this directly
no test coverage detected