KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > sort > Node


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.sort.Node
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (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 {
36     public int balance;
37     public Node leftLink;
38     public Node rightLink;
39     public DataValueDescriptor[] key;
40     public int id;
41     public Node dupChain;
42     public int aux;
43
44     public Node(int id)
45     {
46         this.id = id;
47         reset();
48     }
49
50     public void reset()
51     {
52         balance = 0;
53         leftLink = null;
54         rightLink = null;
55         key = null;
56         dupChain = null;
57         aux = 0;
58         // Leave id alone
59
}
60
61     public Node link(int which)
62     {
63         if (which < 0)
64             return leftLink;
65         else
66             return rightLink;
67     }
68
69     public void setLink(int which, Node l)
70     {
71         if (which < 0)
72             leftLink = l;
73         else
74             rightLink = l;
75     }
76
77     DataValueDescriptor[] getKey()
78     {
79         return key;
80     }
81
82     public String JavaDoc toString()
83     {
84         if (SanityManager.DEBUG)
85         {
86             int lid = (leftLink == null) ? -1 : leftLink.id;
87             int rid = (rightLink == null) ? -1 : rightLink.id;
88             int did = (dupChain == null) ? -1 : dupChain.id;
89             return "{"
90                 + " id=" + id
91                 + " key=" + RowUtil.toString(key)
92                 + " left=" + lid
93                 + " right=" + rid
94                 + " balance=" + balance
95                 + " dupChain=" + did
96                 + " aux= " + aux
97                 + " }";
98         }
99         else
100         {
101             return(null);
102         }
103     }
104 }
105
Popular Tags