| 69 | } |
| 70 | |
| 71 | func (f *array) mergeSpans(ids common.Pgids) { |
| 72 | sort.Sort(ids) |
| 73 | common.Verify(func() { |
| 74 | idsIdx := make(map[common.Pgid]struct{}) |
| 75 | for _, id := range f.ids { |
| 76 | // The existing f.ids shouldn't have duplicated free ID. |
| 77 | if _, ok := idsIdx[id]; ok { |
| 78 | panic(fmt.Sprintf("detected duplicated free page ID: %d in existing f.ids: %v", id, f.ids)) |
| 79 | } |
| 80 | idsIdx[id] = struct{}{} |
| 81 | } |
| 82 | |
| 83 | prev := common.Pgid(0) |
| 84 | for _, id := range ids { |
| 85 | // The ids shouldn't have duplicated free ID. Note page 0 and 1 |
| 86 | // are reserved for meta pages, so they can never be free page IDs. |
| 87 | if prev == id { |
| 88 | panic(fmt.Sprintf("detected duplicated free ID: %d in ids: %v", id, ids)) |
| 89 | } |
| 90 | prev = id |
| 91 | |
| 92 | // The ids shouldn't have any overlap with the existing f.ids. |
| 93 | if _, ok := idsIdx[id]; ok { |
| 94 | panic(fmt.Sprintf("detected overlapped free page ID: %d between ids: %v and existing f.ids: %v", id, ids, f.ids)) |
| 95 | } |
| 96 | } |
| 97 | }) |
| 98 | f.ids = common.Pgids(f.ids).Merge(ids) |
| 99 | } |
| 100 | |
| 101 | func NewArrayFreelist() Interface { |
| 102 | a := &array{ |