X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2FTableHeader.java;fp=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2FTableHeader.java;h=e0b8548561165359ef82a5048375734a7d4821db;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/TableHeader.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/TableHeader.java new file mode 100644 index 000000000..e0b854856 --- /dev/null +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/TableHeader.java @@ -0,0 +1,64 @@ +package org.simantics.db.impl; + +public class TableHeader { + public static final int HEADER_SIZE = 4; + public static final int EXTRA_SIZE = 4; + private final int CAPACITY_INDEX; // Max size of memory than can be used for entries. (Table size without header.) + private final int SIZE_INDEX; // Memory used for entries. + private final int COUNT_INDEX; // Number of elements. + private final int OFFSET_INDEX; // Table offset in containing vector minus zero shift. + private final int EXTRA_INDEX; // Extra header fields for clients. + private int[] header; + TableHeader(int[] header, int headerBase) { + this.CAPACITY_INDEX = headerBase++; + this.SIZE_INDEX = headerBase++; + this.COUNT_INDEX = headerBase++; + this.OFFSET_INDEX = headerBase++; + this.EXTRA_INDEX = headerBase++; + this.header = header; + getOffset(); + getSize(); + getCapacity(); + } + final int getCapacity() { + int ret = header[CAPACITY_INDEX]; + if(ret < 0) throw new IllegalStateException(); + return ret; + } + final void setCapacity(int a) { + header[CAPACITY_INDEX] = a; + } + final int getSize() { + int ret = header[SIZE_INDEX]; + if(ret < 0) throw new IllegalStateException(); + if(ret > getCapacity()) throw new IllegalStateException(); + return ret; + } + final void setSize(int a) { + header[SIZE_INDEX] = a; + } + public final int getCount() { + return header[COUNT_INDEX]; + } + final void setCount(int a) { + header[COUNT_INDEX] = a; + } + public final int getOffset() { + int ret = header[OFFSET_INDEX]; + if(ret < -1) throw new IllegalStateException(); + return ret; + } + final void setOffset(int a) { + header[OFFSET_INDEX] = a; + } + final int getExtra(int index) { + if (index < 0 || index >= EXTRA_SIZE) + throw new IllegalArgumentException(); + return header[EXTRA_INDEX + index]; + } + final void setExtra(int index, int a) { + if (index < 0 || index >= EXTRA_SIZE) + throw new IllegalArgumentException(); + header[EXTRA_INDEX + index] = a; + } +} \ No newline at end of file