1 /*******************************************************************************
2 * Copyright (c) 2012 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
.tmf
.core
.statesystem
.backend
.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.
25 class CoreNode
extends HTNode
{
27 /* Nb. of children this node has */
28 private int nbChildren
;
30 /* Seq. numbers of the children nodes (size = MAX_NB_CHILDREN) */
31 private int[] children
;
33 /* Start times of each of the children (size = MAX_NB_CHILDREN) */
34 private long[] childStart
;
36 /* Seq number of this node's extension. -1 if none */
37 private int extension
;
40 * Initial constructor. Use this to initialize a new EMPTY node.
43 * The HistoryTree to which this node belongs
45 * The (unique) sequence number assigned to this particular node
46 * @param parentSeqNumber
47 * The sequence number of this node's parent node
49 * The earliest timestamp stored in this node
51 CoreNode(HistoryTree tree
, int seqNumber
, int parentSeqNumber
,
53 super(tree
, seqNumber
, parentSeqNumber
, start
);
57 * We instantiate the two following arrays at full size right away,
58 * since we want to reserve that space in the node's header.
59 * "this.nbChildren" will tell us how many relevant entries there are in
62 this.children
= new int[ownerTree
.config
.maxChildren
];
63 this.childStart
= new long[ownerTree
.config
.maxChildren
];
67 protected void readSpecificHeader(ByteBuffer buffer
) {
70 extension
= buffer
.getInt();
71 nbChildren
= buffer
.getInt();
73 children
= new int[ownerTree
.config
.maxChildren
];
74 for (i
= 0; i
< nbChildren
; i
++) {
75 children
[i
] = buffer
.getInt();
77 for (i
= nbChildren
; i
< ownerTree
.config
.maxChildren
; i
++) {
81 this.childStart
= new long[ownerTree
.config
.maxChildren
];
82 for (i
= 0; i
< nbChildren
; i
++) {
83 childStart
[i
] = buffer
.getLong();
85 for (i
= nbChildren
; i
< ownerTree
.config
.maxChildren
; i
++) {
91 protected void writeSpecificHeader(ByteBuffer buffer
) {
94 buffer
.putInt(extension
);
95 buffer
.putInt(nbChildren
);
97 /* Write the "children's seq number" array */
98 for (i
= 0; i
< nbChildren
; i
++) {
99 buffer
.putInt(children
[i
]);
101 for (i
= nbChildren
; i
< ownerTree
.config
.maxChildren
; i
++) {
105 /* Write the "children's start times" array */
106 for (i
= 0; i
< nbChildren
; i
++) {
107 buffer
.putLong(childStart
[i
]);
109 for (i
= nbChildren
; i
< ownerTree
.config
.maxChildren
; i
++) {
114 int getNbChildren() {
118 int getChild(int index
) {
119 return children
[index
];
122 int getLatestChild() {
123 return children
[nbChildren
- 1];
126 long getChildStart(int index
) {
127 return childStart
[index
];
130 long getLatestChildStart() {
131 return childStart
[nbChildren
- 1];
134 int getExtensionSequenceNumber() {
139 * Tell this node that it has a new child (Congrats!)
142 * The SHTNode object of the new child
144 void linkNewChild(CoreNode childNode
) {
145 assert (this.nbChildren
< ownerTree
.config
.maxChildren
);
147 this.children
[nbChildren
] = childNode
.getSequenceNumber();
148 this.childStart
[nbChildren
] = childNode
.getNodeStart();
153 protected byte getNodeType() {
158 protected int getTotalHeaderSize() {
160 specificSize
= 4 /* 1x int (extension node) */
161 + 4 /* 1x int (nbChildren) */
163 /* MAX_NB * int ('children' table) */
164 + 4 * ownerTree
.config
.maxChildren
166 /* MAX_NB * Timevalue ('childStart' table) */
167 + 8 * ownerTree
.config
.maxChildren
;
169 return getCommonHeaderSize() + specificSize
;
173 protected String
toStringSpecific() {
174 /* Only used for debugging, shouldn't be externalized */
175 return "Core Node, " + nbChildren
+ " children, "; //$NON-NLS-1$ //$NON-NLS-2$
This page took 0.037088 seconds and 5 git commands to generate.