openglobus/src/og/Stack.js
Zemledelec febe57e601 Merge branch 'master' into geo_object_instancing
# Conflicts:
#	src/og/entity/Entity.js
#	src/og/math/Mat4.js
#	src/og/webgl/Handler.js
#	src/og/webgl/callbacks.js
#	tests/Globe.test.js
2021-11-13 00:07:12 +03:00

54 lines
1005 B
JavaScript

/**
* @module og/Stack
*/
"use strict";
class Node {
constructor() {
this.next = null;
this.prev = null;
this.data = null;
}
}
class Stack {
/**
*
* @param {number} [size]
*/
constructor(size = 256) {
this._current = new Node();
this._head = this._current;
for (var i = 0; i < size; i++) {
var n = new Node();
n.prev = this._current;
this._current.next = n;
this._current = n;
}
this._current = this._head;
}
current() {
return this._current;
}
push(data) {
this._current = this._current.next;
this._current.data = data;
}
pop(data) {
this._current = this._current.prev;
return this._current.next.data;
}
popPrev(data) {
this._current = this._current.prev;
return this._current.data;
}
}
export { Stack };