LeveledPriorityQueue .java

net.minecraft.world.level.lighting.LeveledPriorityQueue (class): members: firstQueuedLevel, dequeue, enqueue, queues, removeFirstLong, levelCount, isEmpty.

net.minecraft.world.level.lightingclass69 linescommon1.7 KB

API Surface (5)

void rehash(final int newN)
long removeFirstLong()
boolean isEmpty()
void dequeue(final long node, final int key, final int upperBound)
void enqueue(final long node, final int key)

Fields & Constants (3)

levelCount
queues
firstQueuedLevel

Full Source

LeveledPriorityQueue.java69 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level.lighting;
2
3
import it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet;
4
5
public class LeveledPriorityQueue {
6
	private final int levelCount;
7
	private final LongLinkedOpenHashSet[] queues;
8
	private int firstQueuedLevel;
9
10
	public LeveledPriorityQueue(final int levelCount, final int minSize) {
11
		this.levelCount = levelCount;
12
		this.queues = new LongLinkedOpenHashSet[levelCount];
13
14
		for (int i = 0; i < levelCount; i++) {
15
			this.queues[i] = new LongLinkedOpenHashSet(minSize, 0.5F) {
16
				@Override
17
				protected void rehash(final int newN) {
18
					if (newN > minSize) {
19
						super.rehash(newN);
20
					}
21
				}
22
			};
23
		}
24
25
		this.firstQueuedLevel = levelCount;
26
	}
27
28
	public long removeFirstLong() {
29
		LongLinkedOpenHashSet queue = this.queues[this.firstQueuedLevel];
30
		long result = queue.removeFirstLong();
31
		if (queue.isEmpty()) {
32
			this.checkFirstQueuedLevel(this.levelCount);
33
		}
34
35
		return result;
36
	}
37
38
	public boolean isEmpty() {
39
		return this.firstQueuedLevel >= this.levelCount;
40
	}
41
42
	public void dequeue(final long node, final int key, final int upperBound) {
43
		LongLinkedOpenHashSet queue = this.queues[key];
44
		queue.remove(node);
45
		if (queue.isEmpty() && this.firstQueuedLevel == key) {
46
			this.checkFirstQueuedLevel(upperBound);
47
		}
48
	}
49
50
	public void enqueue(final long node, final int key) {
51
		this.queues[key].add(node);
52
		if (this.firstQueuedLevel > key) {
53
			this.firstQueuedLevel = key;
54
		}
55
	}
56
57
	private void checkFirstQueuedLevel(final int upperBound) {
58
		int oldLevel = this.firstQueuedLevel;
59
		this.firstQueuedLevel = upperBound;
60
61
		for (int i = oldLevel + 1; i < upperBound; i++) {
62
			if (!this.queues[i].isEmpty()) {
63
				this.firstQueuedLevel = i;
64
				break;
65
			}
66
		}
67
	}
68
}
69

Decompiled Minecraft 26.3 source of LeveledPriorityQueue (net/minecraft/world/level/lighting/LeveledPriorityQueue.java) with Mojang official mappings, stored verbatim on the site.