Inserts a new record. @param pre record PRE @param id record ID @param c number of inserted records
(final int pre, final int id, final int c)
| 118 | * @param c number of inserted records |
| 119 | */ |
| 120 | public void insert(final int pre, final int id, final int c) { |
| 121 | if(rows == 0 && pre == id && id == baseid + 1) { |
| 122 | // no mapping, and we append at the end => nothing to do |
| 123 | baseid += c; |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | int pos = 0; |
| 128 | int inc = c; |
| 129 | int oid = pre; |
| 130 | |
| 131 | if(rows > 0) { |
| 132 | pos = Arrays.binarySearch(pres, 0, rows, pre); |
| 133 | if(pos < 0) { |
| 134 | pos = -pos - 1; |
| 135 | if(pos != 0) { |
| 136 | // check if inserting into an existing ID interval |
| 137 | final int prev = pos - 1; |
| 138 | final int prevcnt = nids[prev] - fids[prev] + 1; |
| 139 | final int prevpre = pres[prev]; |
| 140 | |
| 141 | if(pre < prevpre + prevcnt) { |
| 142 | // split the ID interval |
| 143 | final int split = pre - prevpre; |
| 144 | final int fid = fids[prev] + split; |
| 145 | |
| 146 | // add a new next interval |
| 147 | add(pos, pre, fid, nids[prev], incs[prev], oids[prev]); |
| 148 | |
| 149 | // shrink the previous interval |
| 150 | nids[prev] = fid - 1; |
| 151 | incs[prev] -= prevcnt - split; |
| 152 | |
| 153 | oid = oids[prev]; |
| 154 | } else { |
| 155 | oid = pre - incs[prev]; |
| 156 | } |
| 157 | inc += incs[prev]; |
| 158 | } |
| 159 | } else if(pos > 0) { |
| 160 | oid = oids[pos]; |
| 161 | inc += incs[pos - 1]; |
| 162 | } |
| 163 | |
| 164 | increment(pos, c); |
| 165 | } |
| 166 | |
| 167 | // add the new interval |
| 168 | add(pos, pre, id, id + c - 1, inc, oid); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Deletes records. |
nothing calls this directly
no test coverage detected