1
/* -*- tab-width: 4 -*-
3
* Electric(tm) VLSI Design System
5
* Copyright (c) 2009 Sun Microsystems and Static Free Software
7
* Electric(tm) is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3 of the License, or
10
* (at your option) any later version.
12
* Electric(tm) is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with Electric(tm); see the file COPYING. If not, write to
19
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20
* Boston, Mass 02111-1307, USA.
22
package com.sun.electric.tool.simulation;
26
import com.sun.electric.database.geometry.btree.*;
27
import com.sun.electric.database.geometry.btree.unboxed.*;
28
import com.sun.electric.tool.simulation.*;
30
public class BTreeNewSignal extends NewSignalSimpleImpl implements Waveform {
32
public final int numEvents;
33
public final int eventWithMinValue;
34
public final int eventWithMaxValue;
35
private NewSignal.Approximation<ScalarSample> preferredApproximation = null;
36
private final BTree<Double,Double,Serializable> tree;
38
public BTreeNewSignal(int eventWithMinValue,
39
int eventWithMaxValue,
40
BTree<Double,Double,Serializable> tree
42
this.numEvents = tree.size();
43
this.eventWithMinValue = eventWithMinValue;
44
this.eventWithMaxValue = eventWithMaxValue;
45
if (tree==null) throw new RuntimeException();
47
this.preferredApproximation = new BTreeNewSignalApproximation();
50
public synchronized NewSignal.Approximation<ScalarSample> getPreferredApproximation() {
51
return preferredApproximation;
54
protected ScalarSample getSampleForTime(double t, boolean justLessThan) {
55
Double d = tree.getValFromKeyFloor(t);
56
if (d==null) throw new RuntimeException("index out of bounds");
57
return new ScalarSample(d.doubleValue());
60
public int getNumEvents() { return numEvents; }
61
protected int getEventForTime(double t, boolean justLessThan) {
62
return tree.getOrdFromKeyFloor(t);
64
public void getEvent(int index, double[] result) {
65
result[0] = getPreferredApproximation().getTime(index);
66
result[1] = result[2] = getPreferredApproximation().getSample(index).getValue();
69
public NewSignal.Approximation<ScalarSample>
70
getPixelatedApproximation(double t0, double t1, int numRegions) {
71
return new BTreePixelatedApproximation(t0, t1, numRegions);
74
private class BTreeNewSignalApproximation implements NewSignal.Approximation<ScalarSample> {
75
public int getNumEvents() { return numEvents; }
76
public double getTime(int index) {
77
Double d = tree.getKeyFromOrd(index);
78
if (d==null) throw new RuntimeException("index out of bounds");
79
return d.doubleValue();
81
public ScalarSample getSample(int index) {
82
Double d = tree.getValFromOrd(index);
83
if (d==null) throw new RuntimeException("index out of bounds");
84
return new ScalarSample(d.doubleValue());
86
public int getTimeNumerator(int index) { throw new RuntimeException("not implemented"); }
87
public int getTimeDenominator() { throw new RuntimeException("not implemented"); }
88
public int getEventWithMaxValue() { return eventWithMaxValue; }
89
public int getEventWithMinValue() { return eventWithMinValue; }
92
private class BTreePixelatedApproximation implements NewSignal.Approximation<ScalarSample> {
94
public BTreePixelatedApproximation(double t0, double t1, int numRegions) {
95
int[] events = new int[numRegions];
97
double stride = (t1-t0)/(numRegions*2);
98
for(int i=0; i<numRegions; i++) {
99
double t = t0 + (2*i+1)*stride;
100
int idx = i==numRegions-1
101
? tree.getOrdFromKeyCeiling(t)
102
: tree.getOrdFromKeyFloor(t);
103
if (j>0 && events[j-1]==idx) idx = tree.getOrdFromKeyCeiling(t);
104
if (j>0 && events[j-1]==idx) continue;
105
if (idx==tree.size()) continue;
106
if (idx==-1) continue;
107
if (j < numRegions-1 && tree.getKeyFromOrd(idx) > t+2*stride) continue;
110
this.events = new int[j];
111
System.arraycopy(events, 0, this.events, 0, j);
113
public int getNumEvents() { return events.length; }
114
public double getTime(int index) {
115
Double d = tree.getKeyFromOrd(events[index]);
116
if (d==null) throw new RuntimeException("index "+index+"/"+events[index]+" out of bounds, size="+tree.size());
117
return d.doubleValue();
119
public ScalarSample getSample(int index) {
120
Double d = tree.getValFromOrd(events[index]);
121
if (d==null) throw new RuntimeException("index out of bounds");
122
return new ScalarSample(d.doubleValue());
124
public int getTimeNumerator(int index) { throw new RuntimeException("not implemented"); }
125
public int getTimeDenominator() { throw new RuntimeException("not implemented"); }
126
public int getEventWithMaxValue() {
127
//return eventWithMaxValue;
128
throw new RuntimeException("not implemented");
130
public int getEventWithMinValue() {
131
//return eventWithMinValue;
132
throw new RuntimeException("not implemented");