4
4
import jokrey .utilities .encoder .EncodableAsBytes ;
5
5
import jokrey .utilities .encoder .as_union .li .LIPosition ;
6
6
import jokrey .utilities .encoder .as_union .li .LIe ;
7
+ import jokrey .utilities .encoder .as_union .li .ReverseLIPosition ;
7
8
import jokrey .utilities .transparent_storage .StorageSystemException ;
8
9
import jokrey .utilities .transparent_storage .TransparentStorage ;
9
10
import jokrey .utilities .transparent_storage .bytes .TransparentBytesStorage ;
@@ -263,20 +264,29 @@ public static long getIntFromByteArray(byte[] bytearr, int from, int len) {
263
264
// }
264
265
// }
265
266
267
+ protected long [] get_next_reverse_li_bounds (ReverseLIPosition start_pos , TransparentStorage <byte []> contentBuilder ) throws StorageSystemException {
268
+ long i = start_pos .pointer ;
269
+ if (i -1 <= 0 )
270
+ return null ;
271
+ byte [] cache = contentBuilder .sub (i -9 , i ); //cache maximum number of required bytes. (to minimize possibly slow sub calls)
272
+
273
+ return get_next_reverse_li_bounds (cache , 0 , i , start_pos .minimum );
274
+ }
275
+
266
276
/**
267
277
* @param partialData all or partial data
268
278
* @param partialDataOffset offset in the partial data
269
279
* @param li_offset latest index in the data
270
- * @param totalDataSize last index of total data(+1) of which partial data is a part of
280
+ * @param minimum first index of total data of which partial data is a part of (usually 0, or header-offset)
271
281
* @return Length indicated indices. The range between those indices is the encoded, connected data.
272
282
*/
273
- public static long [] get_next_reverse_li_bounds (byte [] partialData , int partialDataOffset , long li_offset , long totalDataSize ) {
283
+ public static long [] get_next_reverse_li_bounds (byte [] partialData , int partialDataOffset , long li_offset , long minimum ) {
274
284
if (partialDataOffset < 0 ) return null ;
275
285
276
286
byte leading_li = partialData [partialDataOffset ];
277
287
278
288
long lengthIndicator_asInt = getIntFromByteArray (partialData , partialDataOffset -leading_li , leading_li );
279
- if (lengthIndicator_asInt ==-1 || li_offset + lengthIndicator_asInt > totalDataSize )
289
+ if (lengthIndicator_asInt ==-1 || li_offset - lengthIndicator_asInt < minimum )
280
290
return null ;
281
291
li_offset -=leading_li + 1 ; //to skip the li information.
282
292
return new long []{li_offset - lengthIndicator_asInt , li_offset };
@@ -296,4 +306,28 @@ public static byte[] generateReverseLI(long length) {
296
306
li_bytes [n ] = BitHelper .getByte (length , (li_bytes .length -2 )-n );
297
307
return li_bytes ;
298
308
}
309
+
310
+ public long reverseSkipEntry (ReverseLIPosition pos ) {
311
+ long [] startIndex_endIndex_ofNextLI = get_next_reverse_li_bounds (pos , getStorageSystem ());
312
+ if (startIndex_endIndex_ofNextLI != null ) {
313
+ pos .pointer = startIndex_endIndex_ofNextLI [1 ];
314
+ return startIndex_endIndex_ofNextLI [1 ] - startIndex_endIndex_ofNextLI [0 ];
315
+ }
316
+ return -1 ;
317
+ }
318
+
319
+ public byte [] reverseDecode (ReverseLIPosition pos , boolean delete_decoded ) {
320
+ long [] startIndex_endIndex_ofNextLI = get_next_reverse_li_bounds (pos , getStorageSystem ());
321
+ if (startIndex_endIndex_ofNextLI != null ) {
322
+ byte [] decoded = getStorageSystem ().sub (startIndex_endIndex_ofNextLI [0 ], startIndex_endIndex_ofNextLI [1 ]);
323
+ if (delete_decoded ) {
324
+ getStorageSystem ().delete (startIndex_endIndex_ofNextLI [0 ], pos .pointer );
325
+ } else {
326
+ pos .pointer = startIndex_endIndex_ofNextLI [0 ];
327
+ }
328
+ return decoded ;
329
+ } else {
330
+ return null ;
331
+ }
332
+ }
299
333
}
0 commit comments