All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jtransc.game.util.StackPool Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating Javascript and Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.5.0
Show newest version
package com.jtransc.game.util;

import java.util.ArrayList;

public class StackPool {
	public interface Generator {
		T generate(int index);
	}

	final int capacity;
	final Generator generator;
	private ArrayList values = new ArrayList();
	private int index = 0;

	public StackPool(int capacity, Generator generator) {
		this.capacity = capacity;
		this.generator = generator;
		ensure(capacity);
	}

	private void ensure(int count) {
		while (values.size() < count) values.add(generator.generate(values.size()));
	}

	public int getLength() {
		return index;
	}

	public T push() {
		ensure(index);
		return values.get(index++);
	}

	public T pop() {
		return values.get(--index);
	}

	public void clear() {
		index = 0;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy