add TreeMap facade

This commit is contained in:
Eyck Jentzsch 2021-02-26 11:57:54 +00:00
parent 0e49a68e09
commit d65803a4b7
13 changed files with 178 additions and 39 deletions

View File

@ -29,6 +29,10 @@
id="org.eclipse.emf.common"
version="0.0.0"/>
<includes
id="org.eclipse.collections.feature"
version="0.0.0"/>
<requires>
<import plugin="org.eclipse.core.expressions" version="3.2.0" match="compatible"/>
<import plugin="org.eclipse.core.filesystem" version="1.3.0" match="compatible"/>

View File

@ -14,12 +14,12 @@ import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.TreeMap;
import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
import com.minres.scviewer.database.EventList;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.RelationTypeFactory;
@ -35,7 +35,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
private Integer maxConcurrency;
private TreeMap<Long, IEvent[]> events;
private IEventList<Long, IEvent[]> events;
private List<RelationType> usedRelationsList;
@ -71,9 +71,9 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
}
@Override
public NavigableMap<Long, IEvent[]> getEvents(){
public IEventList<Long, IEvent[]> getEvents(){
if(events==null){
events=new TreeMap<>();
events=new EventList<>();
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
putEvent(new TxEvent(EventKind.END, entry.getValue()));

View File

@ -15,11 +15,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.TreeMap;
import com.minres.scviewer.database.EventList;
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.WaveformType;
import com.minres.scviewer.database.tx.ITx;
@ -39,7 +39,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
protected TextDbLoader loader;
/** The events. */
TreeMap<Long, IEvent[]> events = new TreeMap<>();
IEventList<Long, IEvent[]> events = new EventList<Long, IEvent[]>();
/** The max concurrency. */
private int rowCount = -1;
@ -89,7 +89,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
* @return the events
*/
@Override
public NavigableMap<Long, IEvent[]> getEvents() {
public IEventList<Long, IEvent[]> getEvents() {
return events;
}

View File

@ -83,7 +83,7 @@ public class ArrowPainter implements IPainter {
}
private int getConcurrencyIndex(ITx tx) {
IEvent[] eventList = tx.getStream().getEvents().floorEntry(tx.getBeginTime()).getValue();
IEvent[] eventList = tx.getStream().getEventsBeforeTime(tx.getBeginTime());
Optional<Integer> res = Arrays.stream(eventList).map(e -> ((ITxEvent)e).getRowIndex()).findFirst();
return res.isPresent()? res.get():0;
}

View File

@ -13,7 +13,6 @@ package com.minres.scviewer.database.ui.swt.internal;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.NavigableMap;
import javax.swing.JPanel;
@ -27,6 +26,7 @@ import org.eclipse.swt.graphics.Rectangle;
import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.DoubleVal;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.WaveformColors;
@ -112,7 +112,7 @@ public class SignalPainter extends TrackPainter {
proj.setForeground(this.waveCanvas.styleProvider.getColor(WaveformColors.LINE));
proj.setLineStyle(SWT.LINE_SOLID);
proj.setLineWidth(1);
NavigableMap<Long, IEvent[]> entries = signal.getEvents().subMap(first.getKey(), false, last.getKey(), true);
IEventList<Long, IEvent[]> entries = signal.getEvents().subMap(first.getKey(), false, last.getKey(), true);
SignalChange left = new SignalChange(first);
SignalChange right = new SignalChange(entries.size() > 0 ? entries.firstEntry() : first);
maxPosX = area.x + area.width;
@ -161,7 +161,7 @@ public class SignalPainter extends TrackPainter {
} while (left.time < endTime);
}
private SignalStencil getStencil(GC gc, SignalChange left, NavigableMap<Long, IEvent[]> entries) {
private SignalStencil getStencil(GC gc, SignalChange left, IEventList<Long, IEvent[]> entries) {
IEvent val = left.value;
if(val instanceof BitVector) {
BitVector bv = (BitVector) val;
@ -253,7 +253,7 @@ public class SignalPainter extends TrackPainter {
private long maxVal;
private long minVal;
double yRange = (yOffsetB-yOffsetT);
public MultiBitStencilAnalog(NavigableMap<Long, IEvent[]> entries, Object left, boolean continous, boolean signed) {
public MultiBitStencilAnalog(IEventList<Long, IEvent[]> entries, Object left, boolean continous, boolean signed) {
this.continous=continous;
this.signed=signed;
Collection<IEvent[]> values = entries.values();
@ -358,7 +358,7 @@ public class SignalPainter extends TrackPainter {
boolean continous=true;
public RealStencil(NavigableMap<Long, IEvent[]> entries, Object left, boolean continous) {
public RealStencil(IEventList<Long, IEvent[]> entries, Object left, boolean continous) {
this.continous=continous;
Collection<IEvent[]> values = entries.values();
minVal=(Double) left;

View File

@ -11,7 +11,6 @@
package com.minres.scviewer.database.ui.swt.internal;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.TreeMap;
import org.eclipse.swt.SWT;
@ -21,6 +20,7 @@ import org.eclipse.swt.graphics.Rectangle;
import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.database.tx.ITxEvent;
@ -36,6 +36,7 @@ public class StreamPainter extends TrackPainter{
private IWaveform stream;
private int txBase;
private int txHeight;
// TODO: remove TreeMap usage
private TreeMap<ITx, ITxEvent> seenTx;
public StreamPainter(WaveformCanvas waveCanvas, boolean even, TrackEntry trackEntry) {
@ -87,7 +88,7 @@ public class StreamPainter extends TrackPainter{
drawTx(proj, area, ((ITxEvent)txEvent).getTransaction(), ((ITxEvent)txEvent).getRowIndex(), false);
}else{
seenTx.clear();
NavigableMap<Long, IEvent[]> entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true);
IEventList<Long, IEvent[]> entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true);
ITxEvent highlighed=null;
proj.setForeground(this.waveCanvas.styleProvider.getColor(WaveformColors.LINE));
long selectedId=waveCanvas.currentSelection!=null? waveCanvas.currentSelection.getId():-1;
@ -157,7 +158,7 @@ public class StreamPainter extends TrackPainter{
Entry<Long, IEvent[]> firstTx=stream.getEvents().floorEntry(point.x*waveCanvas.getScaleFactor());
if(firstTx!=null){
do {
ITx tx = getTxFromEntry(lane, point.x, firstTx);
ITx tx = getTxFromEntry(lane, point.x, firstTx.getValue());
if(tx!=null) return tx;
firstTx=stream.getEvents().lowerEntry(firstTx.getKey());
}while(firstTx!=null);
@ -173,11 +174,11 @@ public class StreamPainter extends TrackPainter{
this.stream = stream;
}
protected ITx getTxFromEntry(int lane, int offset, Entry<Long, IEvent[]> firstTx) {
protected ITx getTxFromEntry(int lane, int offset, IEvent[] firstTx) {
long timePoint=offset*waveCanvas.getScaleFactor();
long timePointLow=(offset-5)*waveCanvas.getScaleFactor();
long timePointHigh=(offset+5)*waveCanvas.getScaleFactor();
for(IEvent e:firstTx.getValue()){
for(IEvent e:firstTx){
if(e instanceof ITxEvent) {
ITxEvent evt = (ITxEvent) e;
ITx tx=evt.getTransaction();

View File

@ -21,7 +21,6 @@ import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.TreeMap;
@ -79,6 +78,7 @@ import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.DoubleVal;
import com.minres.scviewer.database.EventKind;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.RelationType;
import com.minres.scviewer.database.WaveformType;
@ -259,11 +259,11 @@ public class WaveformView implements IWaveformView {
Entry<Long, IEvent[]> ceilEntry = null;
if (o instanceof TrackEntry) {
TrackEntry entry = (TrackEntry) o;
NavigableMap<Long, IEvent[]> map = entry.waveform.getEvents();
IEventList<Long, IEvent[]> map = entry.waveform.getEvents();
floorEntry = map.floorEntry(time);
ceilEntry = map.ceilingEntry(time);
} else if (o instanceof ITx) {
NavigableMap<Long, IEvent[]> map = ((ITx) o).getStream().getEvents();
IEventList<Long, IEvent[]> map = ((ITx) o).getStream().getEvents();
floorEntry = map.floorEntry(time);
ceilEntry = map.ceilingEntry(time);
}
@ -958,7 +958,7 @@ public class WaveformView implements IWaveformView {
return;
TrackEntry sel = currentWaveformSelection.get(0);
long time = getCursorTime();
NavigableMap<Long, ?> map = null;
IEventList<Long, ?> map = null;
if (sel.waveform.getType() == WaveformType.TRANSACTION || sel.waveform.getType() == WaveformType.SIGNAL) {
map = sel.waveform.getEvents();
}

View File

@ -20,8 +20,6 @@ import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.Vector;
import java.util.zip.GZIPInputStream;
@ -29,6 +27,7 @@ import com.google.common.collect.Iterables;
import com.minres.scviewer.database.BitVector;
import com.minres.scviewer.database.DoubleVal;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbLoader;
@ -118,14 +117,14 @@ public class VCDDbLoader implements IWaveformDbLoader, IVCDDatabaseBuilder {
if(!res) throw new InputFormatException("Could not parse VCD file");
// calculate max time of this database
for(IWaveform waveform:signals) {
NavigableMap<Long, IEvent[]> events =waveform.getEvents();
IEventList<Long, IEvent[]> events =waveform.getEvents();
if(!events.isEmpty())
maxTime= Math.max(maxTime, events.lastKey());
}
// extend signals to have a last value set at max time
for(IWaveform s:signals){
if(s instanceof VCDSignal<?>) {
TreeMap<Long,?> events = (TreeMap<Long, ?>) ((VCDSignal<?>)s).getEvents();
IEventList<Long, IEvent[]> events = ((VCDSignal<?>)s).getEvents();
if(events.size()>0 && events.lastKey()<maxTime){
Object val = events.lastEntry().getValue();
if(val instanceof BitVector) {

View File

@ -11,11 +11,11 @@
package com.minres.scviewer.database.vcd;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.TreeMap;
import com.minres.scviewer.database.EventList;
import com.minres.scviewer.database.HierNode;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.WaveformType;
@ -27,7 +27,7 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
private final int width;
private NavigableMap<Long, IEvent[]> values;
private IEventList<Long, IEvent[]> values;
public VCDSignal(String name) {
this(0, name, 1);
@ -42,7 +42,7 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
fullName=name;
this.id=id;
this.width=width;
this.values=new TreeMap<>();
this.values=new EventList<>();
}
public VCDSignal(VCDSignal<T> o, int id, String name) {
@ -80,7 +80,7 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
}
@Override
public NavigableMap<Long, IEvent[]> getEvents() {
public IEventList<Long, IEvent[]> getEvents() {
return values;
}

View File

@ -0,0 +1,100 @@
package com.minres.scviewer.database;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.TreeMap;
public class EventList<K,V> implements IEventList<K,V>{
NavigableMap<K,V> backing ;
public EventList() {
backing=new TreeMap<>();
}
public EventList(NavigableMap<K, V> subMap) {
backing=subMap;
}
@Override
public Entry<K, V> floorEntry(K key) {
return backing.floorEntry(key);
}
@Override
public Entry<K, V> ceilingEntry(K key) {
return backing.ceilingEntry(key);
}
@Override
public Entry<K, V> firstEntry() {
return backing.firstEntry();
}
@Override
public Entry<K, V> lastEntry() {
return backing.lastEntry();
}
@Override
public V get(K key) {
return backing.get(key);
}
@Override
public Entry<K, V> higherEntry(K key) {
return backing.higherEntry(key);
}
@Override
public Entry<K, V> lowerEntry(K key) {
return backing.lowerEntry(key);
}
@Override
public IEventList<K, V> subMap(K key, boolean b, K key2, boolean c) {
return new EventList<K,V>( backing.subMap(key, b, key2, c));
}
@Override
public int size() {
return backing.size();
}
@Override
public Collection<K> keys() {
return backing.keySet();
}
@Override
public Collection<V> values() {
return backing.values();
}
@Override
public boolean containsKey(K key) {
return backing.containsKey(key);
}
@Override
public V put(K key, V value) {
return backing.put(key, value);
}
@Override
public Collection<Entry<K, V>> entrySet() {
return backing.entrySet();
}
@Override
public boolean isEmpty() {
return backing.isEmpty();
}
@Override
public K lastKey() {
return backing.lastKey();
}
}

View File

@ -0,0 +1,40 @@
package com.minres.scviewer.database;
import java.util.Collection;
import java.util.Map.Entry;
public interface IEventList<K,V> {
Entry<K, V> floorEntry(K key);
Entry<K, V> ceilingEntry(K key);
Entry<K, V> firstEntry();
Entry<K, V> lastEntry();
V get(K key);
Entry<K, V> higherEntry(K key);
Entry<K, V> lowerEntry(K key);
IEventList<K, V> subMap(K key, boolean b, K key2, boolean c);
int size();
Collection<K> keys();
Collection<V> values();
boolean containsKey(K key);
V put(K key, V value);
Collection<Entry<K, V>> entrySet();
boolean isEmpty();
K lastKey();
}

View File

@ -10,7 +10,6 @@
*******************************************************************************/
package com.minres.scviewer.database;
import java.util.NavigableMap;
// TODO: Auto-generated Javadoc
/**
@ -40,7 +39,7 @@ public interface IWaveform extends IHierNode {
*
* @return the events
*/
public NavigableMap<Long, IEvent[]> getEvents();
public IEventList<Long, IEvent[]> getEvents();
/**
* Gets the events at time.

View File

@ -51,17 +51,13 @@
<feature id="com.minres.scviewer.e4.platform.feature" installMode="root"/>
<feature id="org.eclipse.equinox.p2.core.feature" installMode="root"/>
<feature id="org.eclipse.emf.ecore" installMode="root"/>
<feature id="org.eclipse.rcptt.core" installMode="root"/>
<feature id="org.eclipse.emf.common" installMode="root"/>
<feature id="org.eclipse.ecf.core.feature" installMode="root"/>
<feature id="org.eclipse.ecf.filetransfer.httpclient45.feature" installMode="root"/>
<feature id="org.eclipse.rcptt.ecl.core" installMode="root"/>
<feature id="org.eclipse.ecf.filetransfer.feature" installMode="root"/>
<feature id="org.eclipse.rcptt.tesla" installMode="root"/>
<feature id="org.eclipse.ecf.core.ssl.feature" installMode="root"/>
<feature id="com.minres.scviewer.ui.feature" installMode="root"/>
<feature id="org.eclipse.ecf.filetransfer.ssl.feature" installMode="root"/>
<feature id="org.eclipse.rcptt.tesla.ecl" installMode="root"/>
<feature id="org.eclipse.equinox.executable" installMode="root"/>
<feature id="com.minres.scviewer.database.feature" installMode="root"/>
<feature id="org.eclipse.e4.rcp" installMode="root"/>