edits
[iotcloud.git] / version2 / src / C / SlotIndexer.cc
1
2 /**
3  * Slot indexer allows slots in both the slot buffer and the new
4  * server response to looked up in a consistent fashion.
5  * @author Brian Demsky
6  * @version 1.0
7  */
8
9 class SlotIndexer {
10         Slot[] updates;
11         SlotBuffer buffer;
12         int64_t firstslotseqnum;
13
14         SlotIndexer(Slot[] _updates, SlotBuffer _buffer) {
15                 buffer = _buffer;
16                 updates = _updates;
17                 firstslotseqnum = updates[0].getSequenceNumber();
18         }
19
20         Slot getSlot(int64_t seqnum) {
21                 if (seqnum >= firstslotseqnum) {
22                         int offset = (int) (seqnum - firstslotseqnum);
23                         if (offset >= updates.length)
24                                 throw new Error("Invalid Slot Sequence Number Reference");
25                         else
26                                 return updates[offset];
27                 } else
28                         return buffer.getSlot(seqnum);
29         }
30 }