void createStringTableFromArray(String[] stringTable) { // why a new heap instead of reseting the old one??? // this.stringHeap = new StringHeap(); this.getStringHeap().reset(); for (int i = 1; i < stringTable.length; i++) { this.getStringHeap().addString(stringTable[i]); } }
private final ArrayList<String> getStringList() { ArrayList<String> stringList = new ArrayList<String>(); stringList.add(null); int pos = this.getStringHeap().getLeastStringCode(); final int end = this.getStringHeap().getLargestStringCode(); while (pos <= end) { stringList.add(this.getStringHeap().getStringForCode(pos)); ++pos; } return stringList; }
void resetStringTable() { this.getStringHeap().reset(); }
public String getStringForCode(int stringCode) { return this.getStringHeap().getStringForCode(stringCode); }
int addString(String s) { return this.getStringHeap().addString(s); }
@Override public final void ll_setCharBufferValue(int fsRef, int featureCode, char[] buffer, int start, int length) { // don't do any index check here, done by inner call final int stringCode = this.getStringHeap().addCharBuffer(buffer, start, length); ll_setIntValue(fsRef, featureCode, stringCode); }
@Override public int ll_getCharBufferValueSize(int fsRef, int featureCode) { final int stringCode = ll_getIntValue(fsRef, featureCode); if (stringCode == NULL) { return -1; } return this.getStringHeap().getCharArrayLength(stringCode); }
@Override public final String ll_getStringValue(int fsRef, int featureCode) { return this.getStringHeap().getStringForCode(ll_getIntValue(fsRef, featureCode)); }
private StringBuilder dumpHeapStoredArray(CASImpl cas, final int iHeap) { StringBuilder sb = new StringBuilder(); int[] heap = cas.getHeap().heap; final int length = heap[iHeap + 1]; sb.append("Array Length: ").append(length).append('['); SlotKind arrayElementKind = typeInfo.slotKinds[1]; switch (arrayElementKind) { case Slot_HeapRef: case Slot_Int: case Slot_Short: case Slot_Byte: case Slot_Boolean: case Slot_Float: for (int i = iHeap + 2; i < iHeap + length + 2; i++) { if (i > iHeap + 2) { sb.append(", "); } sb.append(heap[i]); } break; case Slot_StrRef: StringHeap sh = cas.getStringHeap(); for (int i = iHeap + 2; i < iHeap + length + 2; i++) { if (i > iHeap + 2) { sb.append(", "); } sb.append(sh.getStringForCode(heap[i])); } break; default: throw new RuntimeException("internal error"); } sb.append("] "); return sb; }
@Override public int ll_copyCharBufferValue(int fsRef, int featureCode, char[] buffer, int start) { final int stringCode = ll_getIntValue(fsRef, featureCode); if (stringCode == NULL) { return -1; } return this.getStringHeap().copyCharsToBuffer(stringCode, buffer, start); }
public void setStringValue(int addr, int feat, String s) { final int stringCode = ((s == null) ? NULL : this.getStringHeap().addString(s)); setFeatureValue(addr, feat, stringCode); }
private StringBuilder dumpHeapStoredArray(CASImpl cas) { StringBuilder sb = new StringBuilder(); int[] heap = cas.getHeap().heap; final int length = heap[iHeap + 1]; sb.append("Array Length: ").append(length).append('['); SlotKind arrayElementKind = typeInfo.slotKinds[1]; switch (arrayElementKind) { case Slot_HeapRef: case Slot_Int: case Slot_Short: case Slot_Byte: case Slot_Boolean: case Slot_Float: for (int i = iHeap + 2; i < iHeap + length + 2; i++) { if (i > iHeap + 2) { sb.append(", "); } sb.append(heap[i]); } break; case Slot_StrRef: StringHeap sh = cas.getStringHeap(); for (int i = iHeap + 2; i < iHeap + length + 2; i++) { if (i > iHeap + 2) { sb.append(", "); } sb.append(sh.getStringForCode(heap[i])); } break; default: throw new RuntimeException("internal error"); } sb.append("] "); return sb; }
public final String ll_getStringValueFeatOffset(int fsRef, int featureOffset) { return this.getStringHeap().getStringForCode(ll_getIntValueFeatOffset(fsRef, featureOffset)); }
String printCasInfo(CASImpl cas) { int heapsz= cas.getHeap().getNextId() * 4; StringHeapDeserializationHelper shdh = cas.getStringHeap().serialize(); int charssz = shdh.charHeap.length * 2; int strintsz = cas.getStringHeap().getSize() * 8; int strsz = charssz + strintsz; int fsindexessz = cas.getIndexedFSs().length * 4; int bytessz = cas.getByteHeap().getSize(); int shortsz = cas.getShortHeap().getSize() * 2; int longsz = cas.getLongHeap().getSize() * 8; int total = heapsz + strsz + fsindexessz + bytessz + shortsz + longsz; return String.format("CAS info before compression: totalSize(bytes): %,d%n" + " mainHeap: %,d(%d%%)%n" + " Strings: [%,d(%d%%): %,d chars %,d ints]%n" + " fsIndexes: %,d(%d%%)%n" + " byte/short/long Heaps: [%,d %,d %,d]", total, heapsz, (100L*heapsz)/total, strsz, (100L*strsz)/ total, charssz, strintsz, fsindexessz, (100L*fsindexessz) / total, bytessz, shortsz, longsz ); }
public String printCasInfo(CASImpl cas) { int heapsz= cas.getHeap().getNextId() * 4; StringHeapDeserializationHelper shdh = cas.getStringHeap().serialize(); int charssz = shdh.charHeap.length * 2; int strintsz = cas.getStringHeap().getSize() * 8; int strsz = charssz + strintsz; int fsindexessz = cas.getIndexedFSs().length * 4; int bytessz = cas.getByteHeap().getSize(); int shortsz = cas.getShortHeap().getSize() * 2; int longsz = cas.getLongHeap().getSize() * 8; int total = heapsz + strsz + fsindexessz + bytessz + shortsz + longsz; return String.format("CAS info before compression: totalSize(bytes): %,d%n" + " mainHeap: %,d(%d%%)%n" + " Strings: [%,d(%d%%): %,d chars %,d ints]%n" + " fsIndexes: %,d(%d%%)%n" + " byte/short/long Heaps: [%,d %,d %,d]", total, heapsz, (100L*heapsz)/total, strsz, (100L*strsz)/ total, charssz, strintsz, fsindexessz, (100L*fsindexessz) / total, bytessz, shortsz, longsz ); }
@Override public final void ll_setStringValue(int fsRef, int featureCode, String value) { if (null != value) { final TypeSystemImpl ts = this.svd.casMetadata.ts; String[] stringSet = ts.ll_getStringSet(ts.ll_getRangeType(featureCode)); if (stringSet != null) { final int rc = Arrays.binarySearch(stringSet, value); if (rc < 0) { // Not a legal value. CASRuntimeException e = new CASRuntimeException(CASRuntimeException.ILLEGAL_STRING_VALUE, new String[] { value, ts.ll_getTypeForCode(ts.ll_getRangeType(featureCode)).getName() }); throw e; } } } final int stringAddr = (value == null) ? NULL : this.getStringHeap().addString(value); setFeatureValue(fsRef, featureCode, stringAddr); }
private String getTraceRepOfObj( FeatureImpl fi, int v) { TypeImpl range = (TypeImpl) fi.getRange(); int rangeCode = range.getCode(); if (ll_isRefType(rangeCode)) { if (v == 0) return "null"; // FeatureStructureImpl fs = ll_getFSForRef(v); Type type = getTypeSystemImpl().ll_getTypeForCode(getTypeCode(v)); return ((type == null) ? "unknwn" : MiscImpl.elide(type.getShortName(), 5, false)) + ':' + v; } else if (isStringType(rangeCode)){ String s = this.getStringHeap().getStringForCode(v); s = MiscImpl.elide(s, 50, false); return MiscImpl.replaceWhiteSpace(s, "_"); } else if (isFloatType(rangeCode)) { return Float.toString(int2float(v)); } else if (isBooleanType(rangeCode)) { return (v == 1) ? "true" : "false"; } else if (isLongType(rangeCode)) { return Long.toString(this.getLongHeap().getHeapValue(v)); } else if (isDoubleType(rangeCode)) { return Double.toString(long2double(this.getLongHeap().getHeapValue(v))); } else { return Integer.toString(v); } }
this.getStringHeap().getSize(), this.getByteHeap().getSize(), this.getShortHeap().getSize(),
heapStart = isSerializingDelta ? mark.getNextFSId() : 0; stringHeapObj = cas.getStringHeap(); longHeapObj = cas.getLongHeap(); shortHeapObj = cas.getShortHeap();
void copyFeatures(int trgAddr, int srcAddr) throws CASRuntimeException { int typeCode = getHeapValue(trgAddr); if (typeCode != getHeapValue(srcAddr)) { CASRuntimeException e = new CASRuntimeException(CASRuntimeException.INAPPROP_TYPE); // What's that supposed to mean? Internationalized, my foot. // TODO: fix exception argument. // e.addArgument("Type of source and target feature structures do not // match"); throw (e); } // get features to copy int[] featcodes = getTypeSystem().getLowLevelTypeSystem().ll_getAppropriateFeatures(typeCode); for (int i = 0; i < featcodes.length; i++) { // get range type of this feature Feature feature = getTypeSystem().getLowLevelTypeSystem().ll_getFeatureForCode(featcodes[i]); Type rangeType = feature.getRange(); // get feature code int featCode = ((FeatureImpl) feature).getCode(); // get the value for this feature offset in src fs int val = getHeapValue(srcAddr + this.svd.casMetadata.featureOffset[featCode]); // if this is a string, create a new reference in the string // reference heap // and point to the same string as the string feature in src fs. setFeatureValueNotJournaled(trgAddr, featCode, isStringType(rangeType) ? this.getStringHeap().cloneStringReference(val) : getHeapValue(srcAddr + this.svd.casMetadata.featureOffset[featCode])); } }