forked from CAIDA/walrus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
H3RenderQueue.java
152 lines (128 loc) · 3.74 KB
/
H3RenderQueue.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//
// The Walrus Graph Visualization Tool.
// Copyright (C) 2000,2001,2002 The Regents of the University of California.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// ######END_HEADER######
//
public class H3RenderQueue
{
////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
////////////////////////////////////////////////////////////////////////
public H3RenderQueue(int size)
{
m_data = new long[size];
}
////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS
////////////////////////////////////////////////////////////////////////
public synchronized boolean get(int index, Element element)
{
boolean retval = false;
boolean tryAgain;
do
{
tryAgain = false;
if (index < m_numElements)
{
decode(m_data[index], element);
retval = true;
}
else
{
if (!m_isComplete)
{
m_isWaitingForData = true;
waitIgnore();
tryAgain = true;
}
}
}
while (tryAgain);
return retval;
}
public synchronized int getMaxNumElements()
{
return m_data.length;
}
public synchronized int getCurrentNumElements()
{
return m_numElements;
}
public synchronized boolean isComplete()
{
return m_isComplete;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public synchronized void add(int n, long[] data)
{
System.arraycopy(data, 0, m_data, m_numElements, n);
m_numElements += n;
notifyIfWaiting();
}
public synchronized void clear()
{
m_numElements = 0;
m_isComplete = false;
notifyIfWaiting();
}
public synchronized void end()
{
m_isComplete = true;
notifyIfWaiting();
}
////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
////////////////////////////////////////////////////////////////////////
private void decode(long data, Element element)
{
// See comments for m_transformedData in H3Transformer.java
// for details about the encoding of {data}.
element.type = (int)(data >> 32);
element.data = (int)(data & 0xFFFFFFFF);
}
private synchronized void notifyIfWaiting()
{
if (m_isWaitingForData)
{
m_isWaitingForData = false;
notifyAll();
}
}
private synchronized void waitIgnore()
{
try { wait(); } catch (InterruptedException e) { }
}
////////////////////////////////////////////////////////////////////////
// PRIVATE FIELDS
////////////////////////////////////////////////////////////////////////
private long[] m_data;
private int m_numElements = 0;
private boolean m_isComplete = false;
private boolean m_isWaitingForData = false;
////////////////////////////////////////////////////////////////////////
// PUBLIC CLASSES
////////////////////////////////////////////////////////////////////////
public static class Element
{
public static final int TYPE_NODE = 0;
public static final int TYPE_TREE_LINK = 1;
public static final int TYPE_NONTREE_LINK = 2;
int type;
int data;
}
}