1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
3 * Copyright (c) 2010, 2011 École Polytechnique de Montréal
4 * Copyright (c) 2010, 2011 Alexandre Montplaisir <alexandre.montplaisir@gmail.com>
6 * All rights reserved. This program and the accompanying materials are
7 * made available under the terms of the Eclipse Public License v1.0 which
8 * accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.tmf
.core
.statesystem
.backends
.historytree
;
15 import java
.nio
.ByteBuffer
;
18 * A Core node is a first-level node of a History Tree which is not a leaf node.
20 * It extends HTNode by adding support for child nodes, and also extensions.
22 * @author Alexandre Montplaisir
25 public class CoreNode
extends HTNode
{
27 /** Number of bytes in a int */
28 private static final int SIZE_INT
= 4;
30 /** Number of bytes in a long */
31 private static final int SIZE_LONG
= 8;
33 /** Nb. of children this node has */
34 private int nbChildren
;
36 /** Seq. numbers of the children nodes (size = MAX_NB_CHILDREN) */
37 private int[] children
;
39 /** Start times of each of the children (size = MAX_NB_CHILDREN) */
40 private long[] childStart
;
42 /** Seq number of this node's extension. -1 if none */
43 private int extension
= -1;
46 * Initial constructor. Use this to initialize a new EMPTY node.
49 * Configuration of the History Tree
51 * The (unique) sequence number assigned to this particular node
52 * @param parentSeqNumber
53 * The sequence number of this node's parent node
55 * The earliest timestamp stored in this node
57 protected CoreNode(HTConfig config
, int seqNumber
, int parentSeqNumber
,
59 super(config
, seqNumber
, parentSeqNumber
, start
);
61 int size
= config
.getMaxChildren();
64 * We instantiate the two following arrays at full size right away,
65 * since we want to reserve that space in the node's header.
66 * "this.nbChildren" will tell us how many relevant entries there are in
69 this.children
= new int[size
];
70 this.childStart
= new long[size
];
74 public void readSpecificHeader(ByteBuffer buffer
) {
75 int size
= getConfig().getMaxChildren();
77 extension
= buffer
.getInt();
78 nbChildren
= buffer
.getInt();
80 children
= new int[size
];
81 for (int i
= 0; i
< nbChildren
; i
++) {
82 children
[i
] = buffer
.getInt();
84 for (int i
= nbChildren
; i
< size
; i
++) {
88 this.childStart
= new long[size
];
89 for (int i
= 0; i
< nbChildren
; i
++) {
90 childStart
[i
] = buffer
.getLong();
92 for (int i
= nbChildren
; i
< size
; i
++) {
98 public void writeSpecificHeader(ByteBuffer buffer
) {
99 int size
= getConfig().getMaxChildren();
101 buffer
.putInt(extension
);
102 buffer
.putInt(nbChildren
);
104 /* Write the "children's seq number" array */
105 for (int i
= 0; i
< nbChildren
; i
++) {
106 buffer
.putInt(children
[i
]);
108 for (int i
= nbChildren
; i
< size
; i
++) {
112 /* Write the "children's start times" array */
113 for (int i
= 0; i
< nbChildren
; i
++) {
114 buffer
.putLong(childStart
[i
]);
116 for (int i
= nbChildren
; i
< size
; i
++) {
122 * Return the number of child nodes this node has.
124 * @return The number of child nodes
126 public int getNbChildren() {
131 * Get the child node corresponding to the specified index
133 * @param index The index of the child to lookup
134 * @return The child node
136 public int getChild(int index
) {
137 return children
[index
];
141 * Get the latest (right-most) child node of this node.
143 * @return The latest child node
145 public int getLatestChild() {
146 return children
[nbChildren
- 1];
150 * Get the start time of the specified child node.
153 * The index of the child node
154 * @return The start time of the that child node.
156 public long getChildStart(int index
) {
157 return childStart
[index
];
161 * Get the start time of the latest (right-most) child node.
163 * @return The start time of the latest child
165 public long getLatestChildStart() {
166 return childStart
[nbChildren
- 1];
170 * Get the sequence number of the extension to this node (if there is one).
172 * @return The sequence number of the extended node. '-1' is returned if
173 * there is no extension node.
175 public int getExtensionSequenceNumber() {
180 * Tell this node that it has a new child (Congrats!)
183 * The SHTNode object of the new child
185 public void linkNewChild(CoreNode childNode
) {
186 assert (this.nbChildren
< getConfig().getMaxChildren());
188 this.children
[nbChildren
] = childNode
.getSequenceNumber();
189 this.childStart
[nbChildren
] = childNode
.getNodeStart();
194 public byte getNodeType() {
199 public int getTotalHeaderSize() {
200 int maxChildren
= getConfig().getMaxChildren();
202 SIZE_INT
/* 1x int (extension node) */
203 + SIZE_INT
/* 1x int (nbChildren) */
205 /* MAX_NB * int ('children' table) */
206 + SIZE_INT
* maxChildren
208 /* MAX_NB * Timevalue ('childStart' table) */
209 + SIZE_LONG
* maxChildren
;
211 return COMMON_HEADER_SIZE
+ specificSize
;
215 public String
toStringSpecific() {
216 /* Only used for debugging, shouldn't be externalized */
217 return "Core Node, " + nbChildren
+ " children, "; //$NON-NLS-1$ //$NON-NLS-2$
This page took 0.042584 seconds and 5 git commands to generate.