3 var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
5 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7 var SlotBuffer = function () {
8 function SlotBuffer() {
9 _classCallCheck(this, SlotBuffer);
11 this.DEFAULT_SIZE = 128;
18 _createClass(SlotBuffer, [{
20 value: function size() {
21 if (this.head >= this.tail) {
22 return this.head - this.tail;
24 return this.array.length + this.head - this.tail;
28 value: function capacity() {
29 return this.array.length - 1;
33 value: function resize(newsize) {
34 if (newsize === this.array.length - 1) {
38 var currsize = this.size();
39 var index = this.tail;
40 for (var i = 0; i < currsize; i++) {
41 newarray[i] = this.array[index];
42 if (++index === this.array.length) {
45 this.array = newarray;
52 value: function incrementHead() {
54 if (this.head >= this.array.length) {
60 value: function incrementTail() {
62 if (this.tail >= this.array.length) {
68 value: function putSlot(s) {
69 if (!(s instanceof Slot)) {
70 throw new Error("Error with arguments. Argument should be a slot object");
72 this.array[this.head] = s;
75 if (this.oldestseqn === 0) {
76 this.oldestseqn = s.getSequenceNumber();
79 if (this.head === this.tail) {
86 value: function getSlot(seqnum) {
87 var diff = seqnum - this.oldestseqn;
88 var index = diff + this.tail;
89 if (index >= this.array.length) {
90 if (this.head >= this.tail) {
93 index = index - this.array.length;
95 if (index >= this.array.length) {
99 if (this.head >= this.tail && index >= this.head) {
103 return this.array[index];
106 key: "getOldestSeqNum",
107 value: function getOldestSeqNum() {
108 return this.oldestseqn;
111 key: "getNewestSeqNum",
112 value: function getNewestSeqNum() {
113 return this.oldestseqn + this.size() - 1;