1 | /* |
2 | |
3 | Derby - Class org.apache.derby.impl.store.access.sort.Node |
4 | |
5 | Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.impl.store.access.sort; |
22 | |
23 | import org.apache.derby.iapi.services.sanity.SanityManager; |
24 | import org.apache.derby.iapi.types.DataValueDescriptor; |
25 | import org.apache.derby.impl.sql.execute.RowUtil; |
26 | |
27 | /** |
28 | A node in a balanced binary tree. This class is effectively a |
29 | struct to the balanced tree class. |
30 | |
31 | **/ |
32 | |
33 | final class Node |
34 | { |
35 | public int balance; |
36 | public Node leftLink; |
37 | public Node rightLink; |
38 | public DataValueDescriptor[] key; |
39 | public int id; |
40 | public Node dupChain; |
41 | public int aux; |
42 | |
43 | public Node(int id) |
44 | { |
45 | this.id = id; |
46 | reset(); |
47 | } |
48 | |
49 | public void reset() |
50 | { |
51 | balance = 0; |
52 | leftLink = null; |
53 | rightLink = null; |
54 | key = null; |
55 | dupChain = null; |
56 | aux = 0; |
57 | // Leave id alone |
58 | } |
59 | |
60 | public Node link(int which) |
61 | { |
62 | if (which < 0) |
63 | return leftLink; |
64 | else |
65 | return rightLink; |
66 | } |
67 | |
68 | public void setLink(int which, Node l) |
69 | { |
70 | if (which < 0) |
71 | leftLink = l; |
72 | else |
73 | rightLink = l; |
74 | } |
75 | |
76 | DataValueDescriptor[] getKey() |
77 | { |
78 | return key; |
79 | } |
80 | |
81 | public String toString() |
82 | { |
83 | if (SanityManager.DEBUG) |
84 | { |
85 | int lid = (leftLink == null) ? -1 : leftLink.id; |
86 | int rid = (rightLink == null) ? -1 : rightLink.id; |
87 | int did = (dupChain == null) ? -1 : dupChain.id; |
88 | return "{" |
89 | + " id=" + id |
90 | + " key=" + RowUtil.toString(key) |
91 | + " left=" + lid |
92 | + " right=" + rid |
93 | + " balance=" + balance |
94 | + " dupChain=" + did |
95 | + " aux= " + aux |
96 | + " }"; |
97 | } |
98 | else |
99 | { |
100 | return(null); |
101 | } |
102 | } |
103 | } |