Example #1
0
  @Override
  public void copyNormalizedKey(MemorySegment target, int offset, int len) {
    // cache variables on stack, avoid repeated dereferencing of "this"
    final char[] chars = this.value;
    final int limit = offset + len;
    final int end = this.len;
    int pos = 0;

    while (pos < end && offset < limit) {
      char c = chars[pos++];
      if (c < HIGH_BIT) {
        target.put(offset++, (byte) c);
      } else if (c < HIGH_BIT2) {
        target.put(offset++, (byte) ((c >>> 7) | HIGH_BIT));
        if (offset < limit) {
          target.put(offset++, (byte) c);
        }
      } else {
        target.put(offset++, (byte) ((c >>> 10) | HIGH_BIT2_MASK));
        if (offset < limit) {
          target.put(offset++, (byte) (c >>> 2));
        }
        if (offset < limit) {
          target.put(offset++, (byte) c);
        }
      }
    }
    while (offset < limit) {
      target.put(offset++, (byte) 0);
    }
  }
 @Override
 public void copyNormalizedKey(MemorySegment target, int offset, int len) {
   // note that the char is an unsigned data type in java and consequently needs
   // no code that transforms the signed representation to an offsetted representation
   // that is equivalent to unsigned, when compared byte by byte
   if (len == 2) {
     // default case, full normalized key
     target.put(offset, (byte) ((value >>> 8) & 0xff));
     target.put(offset + 1, (byte) ((value) & 0xff));
   } else if (len <= 0) {
   } else if (len == 1) {
     target.put(offset, (byte) ((value >>> 8) & 0xff));
   } else {
     target.put(offset, (byte) ((value >>> 8) & 0xff));
     target.put(offset + 1, (byte) ((value) & 0xff));
     for (int i = 2; i < len; i++) {
       target.put(offset + i, (byte) 0);
     }
   }
 }