]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/TableHeader.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / TableHeader.java
1 package org.simantics.db.impl;
2
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.
11     private int[] header;
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++;
18        this.header = header;
19        getOffset();
20        getSize();
21        getCapacity();
22    }
23    final int getCapacity() {
24        int ret = header[CAPACITY_INDEX];
25        if(ret < 0) throw new IllegalStateException();
26        return ret;
27    }
28    final void setCapacity(int a) {
29        header[CAPACITY_INDEX] = a;
30    }
31    final int getSize() {
32        int ret = header[SIZE_INDEX];
33        if(ret < 0) throw new IllegalStateException();
34        if(ret > getCapacity()) throw new IllegalStateException();
35        return ret;
36    }
37    final void setSize(int a) {
38        header[SIZE_INDEX] = a;
39    }
40    public final int getCount() {
41        return header[COUNT_INDEX];
42    }
43    final void setCount(int a) {
44        header[COUNT_INDEX] = a;
45    }
46    public final int getOffset() {
47        int ret = header[OFFSET_INDEX];
48        if(ret < -1) throw new IllegalStateException();
49        return ret; 
50    }
51    final void setOffset(int a) {
52        header[OFFSET_INDEX] = a;
53    }
54    final int getExtra(int index) {
55        if (index < 0 || index >= EXTRA_SIZE)
56            throw new IllegalArgumentException();
57        return header[EXTRA_INDEX + index];
58    }
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;
63    }
64 }