01: /*
02:
03: Derby - Class org.apache.derby.impl.store.access.sort.Node
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21:
22: package org.apache.derby.impl.store.access.sort;
23:
24: import org.apache.derby.iapi.services.sanity.SanityManager;
25: import org.apache.derby.iapi.types.DataValueDescriptor;
26: import org.apache.derby.impl.sql.execute.RowUtil;
27:
28: /**
29: A node in a balanced binary tree. This class is effectively a
30: struct to the balanced tree class.
31:
32: **/
33:
34: final class Node {
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: this .id = id;
45: reset();
46: }
47:
48: public void reset() {
49: balance = 0;
50: leftLink = null;
51: rightLink = null;
52: key = null;
53: dupChain = null;
54: aux = 0;
55: // Leave id alone
56: }
57:
58: public Node link(int which) {
59: if (which < 0)
60: return leftLink;
61: else
62: return rightLink;
63: }
64:
65: public void setLink(int which, Node l) {
66: if (which < 0)
67: leftLink = l;
68: else
69: rightLink = l;
70: }
71:
72: DataValueDescriptor[] getKey() {
73: return key;
74: }
75:
76: public String toString() {
77: if (SanityManager.DEBUG) {
78: int lid = (leftLink == null) ? -1 : leftLink.id;
79: int rid = (rightLink == null) ? -1 : rightLink.id;
80: int did = (dupChain == null) ? -1 : dupChain.id;
81: return "{" + " id=" + id + " key=" + RowUtil.toString(key)
82: + " left=" + lid + " right=" + rid + " balance="
83: + balance + " dupChain=" + did + " aux= " + aux
84: + " }";
85: } else {
86: return (null);
87: }
88: }
89: }
|