MCPcopy Create free account
hub / github.com/BaseXdb/basex / pack

Method pack

basex-core/src/main/java/org/basex/util/Inline.java:45–69  ·  view source on GitHub ↗

Creates a numeric (inlined) representation of the specified token. @param token token to be inlined @return inlined value, or 0 if inlining is not possible

(final byte[] token)

Source from the content-addressed store, hash-verified

43 * @return inlined value, or {@code 0} if inlining is not possible
44 */
45 public static long pack(final byte[] token) {
46 // inline integer value
47 long value = packInt(token);
48 if(value != -1) return value;
49
50 // short token
51 final long tl = token.length;
52 if(tl <= 4) {
53 value = INLINE | STRING | tl << 32;
54 int c = 32;
55 for(final byte b : token) value |= (b & 0xFFL) << (c -= 8);
56 return value;
57 }
58 // compressed whitespace token
59 if(tl < 16 && ws(token)) {
60 value = INLINE | STRING | Compress.COMPRESS | tl << 32;
61 int c = 32;
62 // upper bit: 09/0A = 0, 0D/20 = 1
63 // lower bit: 0A/20 = 0, 09/0D = 1
64 for(final byte b : token) value |= (b < 0x0B ? 0L : 1L) << --c | (long) (b & 1) << --c;
65 return value;
66 }
67 // no inlining possible
68 return 0;
69 }
70
71 /**
72 * Converts the specified token into a positive integer value.

Callers 7

runMethod · 0.95
rejectMethod · 0.95
textRefMethod · 0.95
splashMethod · 0.45
finishMethod · 0.45
initMethod · 0.45
changeMethod · 0.45

Calls 2

packIntMethod · 0.95
wsMethod · 0.45

Tested by 2

runMethod · 0.76
rejectMethod · 0.76