public static int buildToken(int tokenType, int tokenOpps, int id) { assert (id <= MAX_INSTANCE) : "can not index values larger than "+MAX_INSTANCE+" bad value requested was "+id; //NOTE: this also limits the largest fragment size in ints due to Group using this field as the jump delta. assert (TypeMask.toString(tokenType).indexOf("unknown") == -1) : "Unknown type of " + tokenType + " " + Integer.toHexString(tokenType); assert (tokenType >= 0); assert (tokenType <= MASK_TYPE); assert (tokenOpps >= 0); assert (tokenOpps <= MASK_OPER) : "Opps " + Integer.toHexString(tokenOpps); return 0x80000000 | (tokenType << TokenBuilder.SHIFT_TYPE) | (tokenOpps << TokenBuilder.SHIFT_OPER) | id & MAX_INSTANCE; }
public static int buildToken(int tokenType, int tokenOpps, int id) { assert (id <= MAX_INSTANCE) : "can not index values larger than "+MAX_INSTANCE+" bad value requested was "+id; //NOTE: this also limits the largest fragment size in ints due to Group using this field as the jump delta. assert (TypeMask.toString(tokenType).indexOf("unknown") == -1) : "Unknown type of " + tokenType + " " + Integer.toHexString(tokenType); assert (tokenType >= 0); assert (tokenType <= MASK_TYPE); assert (tokenOpps >= 0); assert (tokenOpps <= MASK_OPER) : "Opps " + Integer.toHexString(tokenOpps); return 0x80000000 | (tokenType << TokenBuilder.SHIFT_TYPE) | (tokenOpps << TokenBuilder.SHIFT_OPER) | id & MAX_INSTANCE; }
public static String toString(int ... typeMask) { StringBuilder result = new StringBuilder(); for(int i = 0;i<typeMask.length;i++) { result.append(toString(typeMask[i])); result.append(','); } if (result.length()>0) { result.setLength(result.length()-1); } return result.toString(); } // This method for debugging and therefore can produce garbage.
public static String toString(int ... typeMask) { StringBuilder result = new StringBuilder(); for(int i = 0;i<typeMask.length;i++) { result.append(toString(typeMask[i])); result.append(','); } if (result.length()>0) { result.setLength(result.length()-1); } return result.toString(); } // This method for debugging and therefore can produce garbage.
public static String toString(int ... typeMask) { StringBuilder result = new StringBuilder(); for(int i = 0;i<typeMask.length;i++) { result.append(toString(typeMask[i])); result.append(','); } if (result.length()>0) { result.setLength(result.length()-1); } return result.toString(); } // This method for debugging and therefore can produce garbage.
/** * Reads long bits from specified pipe and converts to double * @param pipe to be read * @param loc location of long bits to read * @return double bits converted from long */ public static double readLongBitsToDouble(Pipe pipe, int loc) { assert((loc&0x1C<<OFF_BITS)==(0x4<<OFF_BITS)) : "Expected to write some type of long but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Double.longBitsToDouble(readLong(pipe,loc)); }
/** * Reads double from specified pipe * @param pipe to be read * @param loc location of double to read * @return data from specified location */ public static double readDouble(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return ((double)readDecimalMantissa(pipe,loc))*powdi[64 - readDecimalExponent(pipe,loc)]; }
/** * Reads decimal exponent from specified pipe * @param pipe to read from * @param loc location to read from * @return decimal */ public static int readDecimalExponent(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readInt(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc)); }
/** * Reads float from specified pipe * @param pipe to be read * @param loc location of float to read * @return data from specified location */ public static float readFloat(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return ((float)readDecimalMantissa(pipe,loc))*powfi[64 - readDecimalExponent(pipe,loc)]; }
/** * Reads decimal mantissa from specified pipe * @param pipe to read from * @param loc location to read from * @return mantissa */ public static long readDecimalMantissa(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readLong(Pipe.slab(pipe), pipe.slabMask, pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc) + 1);//plus one to skip over exponent }
/** * Reads decimal exponent from specified pipe * @param pipe to read from * @param loc location to read from * @return decimal */ public static int readDecimalExponent(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readInt(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc)); }
/** * Reads float from specified pipe * @param pipe to be read * @param loc location of float to read * @return data from specified location */ public static float readFloat(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return ((float)readDecimalMantissa(pipe,loc))*powfi[64 - readDecimalExponent(pipe,loc)]; }
/** * Reads decimal exponent from specified pipe * @param pipe to read from * @param loc location to read from * @return decimal */ public static int readDecimalExponent(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readInt(Pipe.slab(pipe),pipe.slabMask,pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc)); }
/** * Reads decimal mantissa from specified pipe * @param pipe to read from * @param loc location to read from * @return mantissa */ public static long readDecimalMantissa(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readLong(Pipe.slab(pipe), pipe.slabMask, pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc) + 1);//plus one to skip over exponent }
/** * Reads decimal mantissa from specified pipe * @param pipe to read from * @param loc location to read from * @return mantissa */ public static long readDecimalMantissa(Pipe pipe, int loc) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to read some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); return Pipe.readLong(Pipe.slab(pipe), pipe.slabMask, pipe.ringWalker.activeReadFragmentStack[STACK_OFF_MASK&(loc>>STACK_OFF_SHIFT)] + (OFF_MASK&loc) + 1);//plus one to skip over exponent }
/** * Writes float to specific location in pipe * @param pipe to be written to * @param loc location to write * @param value float to be written * @param places to write values in */ public static void writeFloat(Pipe pipe, int loc, float value, int places) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); Pipe.setValues(Pipe.slab(pipe), pipe.slabMask, structuredPositionForLOC(pipe, loc), -places, (long)Math.rint(value*powd[64+places])); }
/** * Writes double to specific location in pipe * @param pipe to be written to * @param loc location to write * @param value double to be written * @param places to write values in */ public static void writeDouble(Pipe pipe, int loc, double value, int places) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); Pipe.setValues(Pipe.slab(pipe), pipe.slabMask, structuredPositionForLOC(pipe, loc), -places, (long)Math.rint(value*powd[64+places])); }
/** * Writes float to specific location in pipe * @param pipe to be written to * @param loc location to write * @param value float to be written * @param places to write values in */ public static void writeFloat(Pipe pipe, int loc, float value, int places) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); Pipe.setValues(Pipe.slab(pipe), pipe.slabMask, structuredPositionForLOC(pipe, loc), -places, (long)Math.rint(value*powd[64+places])); }
/** * Writes double to specific location in pipe * @param pipe to be written to * @param loc location to write * @param value double to be written * @param places to write values in */ public static void writeDouble(Pipe pipe, int loc, double value, int places) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); Pipe.setValues(Pipe.slab(pipe), pipe.slabMask, structuredPositionForLOC(pipe, loc), -places, (long)Math.rint(value*powd[64+places])); }
/** * Writes float to specific location in pipe * @param pipe to be written to * @param loc location to write * @param value float to be written * @param places to write values in */ public static void writeFloat(Pipe pipe, int loc, float value, int places) { assert((loc&0x1E<<OFF_BITS)==(0x0C<<OFF_BITS)) : "Expected to write some type of decimal but found "+TypeMask.toString((loc>>OFF_BITS)&TokenBuilder.MASK_TYPE); Pipe.setValues(Pipe.slab(pipe), pipe.slabMask, structuredPositionForLOC(pipe, loc), -places, (long)Math.rint(value*powd[64+places])); }