1 package net.obsearch.index.ghs;
2
3
4
5
6
7
8
9
10
11
12
13
14
15 public final class FastPriorityQueueLong {
16
17 private long[][] data;
18 private int[] counts;
19 private final int queueSize;
20
21
22
23
24
25 public FastPriorityQueueLong(int maxDistance, int queueSize){
26 maxDistance++;
27 data = new long[maxDistance][queueSize];
28 counts = new int[maxDistance];
29 this.queueSize = queueSize;
30 }
31
32
33
34
35
36
37 public void add(long object, int distance){
38 int index = counts[distance];
39 if(index < queueSize){
40 data[distance][index] = object;
41 counts[distance]++;
42 }
43 }
44
45
46
47
48
49
50
51 public long[] get(){
52 int total = 0;
53 for(int c : counts){
54 total += c;
55 }
56 total = Math.min(total, queueSize);
57 long[] result = new long[total];
58 int i1 = 0;
59
60 int resi = 0;
61 while(i1 < data.length && resi < total){
62 int i2 = 0;
63 while(i2 < counts[i1] && resi < total){
64 result[resi] = data[i1][i2];
65 resi++;
66 i2++;
67 }
68 i1++;
69 }
70 return result;
71 }
72
73 }