-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLSDAbstractTree.java
144 lines (125 loc) · 3.53 KB
/
LSDAbstractTree.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
package skylinebreaker;
import java.util.Arrays;
import java.util.Comparator;
import preference.csv.optimize.LevelManager;
import preference.exception.PreferenceException;
import flatlc.levels.FlatLevelCombination;
public abstract class LSDAbstractTree {
final static int BUCKETSIZE = 10000;
static interface Node
{
DirectoryNode getParent();
}
static public interface LSDAbstractTreeFactory
{
public abstract LSDAbstractTree get(final LevelManager manager, final FlatLevelCombination firstElement) throws PreferenceException;
}
static class DirectoryNode implements Node
{
final int location;
Node left;
Node right;
final DirectoryNode parent;
DirectoryNode(final int location, final Node left, final Node right, final DirectoryNode parent)
{
this.location = location;
this.left = left;
this.right = right;
this.parent = parent;
}
@Override
public DirectoryNode getParent() {
return parent;
}
}
class BucketNode implements Node
{
final FlatLevelCombination[] data = new FlatLevelCombination[BUCKETSIZE];
int reserved = 0;
final int axis;
DirectoryNode parent = null;
BucketNode(final int axis)
{
this.axis = axis;
}
void add(FlatLevelCombination el)
{
data[reserved++] = el;
}
boolean isFull()
{
return reserved+1 == data.length;
}
int splitPoint()
{
Arrays.sort(data, 0, reserved, new AxisProjectionComparator(axis));
return data.length/2; //[data.length/2].getLevel(axis);
}
public FlatLevelCombination[] computeLocalSkyline()
{
for(int i = 0; i < reserved; ++i)
{
outerLoop:
for(int j = i+1; j < reserved; ++j)
{
innerLoop:
//if(data[j] == null) continue;
switch(data[i].compare(data[j])) {
case FlatLevelCombination.LESS:
data[i--] = data[--reserved];
break outerLoop;
case FlatLevelCombination.GREATER:
data[j--] = data[--reserved];
break innerLoop;
}
}
}
return Arrays.copyOf(data, reserved);
}
@Override
public DirectoryNode getParent() {
return parent;
}
}
Node getRoot()
{
return root;
}
protected Node root;
public final int dimensions;
public final LevelManager manager;
public LSDAbstractTree(final LevelManager manager, final FlatLevelCombination firstElement) throws PreferenceException
{
this.manager = manager;
this.dimensions = manager.getBasePreferenceCount();
final BucketNode bn = new BucketNode(getSplitAxis(0));
bn.add(firstElement);
root = bn;
}
public int getLevel(final FlatLevelCombination element, int i)
{
//return element.getLevel(i);
return (int) manager.getBasePref(i).level(manager.getAttributeSelector(i).evaluate(element, null, manager.getBasePref(i).getDomainType()), null);
}
public int getOverallLevel(final FlatLevelCombination element)
{
//return element.getOverallLevel();
int level = 0;
for(int i = 0; i < dimensions; ++i)
level += (int) manager.getBasePref(i).level(manager.getAttributeSelector(i).evaluate(element, null, manager.getBasePref(i).getDomainType()), null);
return level;
}
public abstract void add(final FlatLevelCombination element) throws PreferenceException;
int getSplitAxis(final int depth)
{
return depth % dimensions;
}
private final class AxisProjectionComparator implements Comparator<FlatLevelCombination> {
final int axis;
AxisProjectionComparator(int axis) { this.axis = axis; }
@Override
public int compare(final FlatLevelCombination a, final FlatLevelCombination b) {
return Integer.compare(getLevel(a,axis), getLevel(b,axis));
}
};
}