org.truffleruby.collections.IntStack Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ruby-language Show documentation
Show all versions of ruby-language Show documentation
Core module of Ruby on Truffle
The newest version!
/*
* Copyright (c) 2020, 2024 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 2.0, or
* GNU General Public License version 2, or
* GNU Lesser General Public License version 2.1.
*/
package org.truffleruby.collections;
import org.truffleruby.core.array.ArrayUtils;
public final class IntStack {
int[] storage;
int index = -1;
public IntStack() {
this(16);
}
public IntStack(int length) {
this.storage = new int[length];
}
public boolean isEmpty() {
return index == -1;
}
public void push(int value) {
if (++index == storage.length) {
storage = ArrayUtils.grow(storage, storage.length * 2);
}
storage[index] = value;
}
public int peek() {
return storage[index];
}
public int pop() {
return storage[index--];
}
}