1 package org.simantics.db.impl;
3 public class TableHeader {
4 public static final int HEADER_SIZE = 4;
5 public static final int EXTRA_SIZE = 4;
6 private final int CAPACITY_INDEX; // Max size of memory than can be used for entries. (Table size without header.)
7 private final int SIZE_INDEX; // Memory used for entries.
8 private final int COUNT_INDEX; // Number of elements.
9 private final int OFFSET_INDEX; // Table offset in containing vector minus zero shift.
10 private final int EXTRA_INDEX; // Extra header fields for clients.
12 TableHeader(int[] header, int headerBase) {
13 this.CAPACITY_INDEX = headerBase++;
14 this.SIZE_INDEX = headerBase++;
15 this.COUNT_INDEX = headerBase++;
16 this.OFFSET_INDEX = headerBase++;
17 this.EXTRA_INDEX = headerBase++;
23 final int getCapacity() {
24 int ret = header[CAPACITY_INDEX];
25 if(ret < 0) throw new IllegalStateException();
28 final void setCapacity(int a) {
29 header[CAPACITY_INDEX] = a;
32 int ret = header[SIZE_INDEX];
33 if(ret < 0) throw new IllegalStateException();
34 if(ret > getCapacity()) throw new IllegalStateException();
37 final void setSize(int a) {
38 header[SIZE_INDEX] = a;
40 public final int getCount() {
41 return header[COUNT_INDEX];
43 final void setCount(int a) {
44 header[COUNT_INDEX] = a;
46 public final int getOffset() {
47 int ret = header[OFFSET_INDEX];
48 if(ret < -1) throw new IllegalStateException();
51 final void setOffset(int a) {
52 header[OFFSET_INDEX] = a;
54 final int getExtra(int index) {
55 if (index < 0 || index >= EXTRA_SIZE)
56 throw new IllegalArgumentException();
57 return header[EXTRA_INDEX + index];
59 final void setExtra(int index, int a) {
60 if (index < 0 || index >= EXTRA_SIZE)
61 throw new IllegalArgumentException();
62 header[EXTRA_INDEX + index] = a;