some more refactoring

This commit is contained in:
Eyck Jentzsch 2021-02-27 13:47:37 +00:00
parent 1d2395e00d
commit 71297c4e5a
7 changed files with 23 additions and 35 deletions

View File

@ -84,16 +84,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
}
private void putEvent(TxEvent ev){
Long time = ev.getTime();
if(events.containsKey(time)) {
IEvent[] oldV = events.get(time);
IEvent[] newV = new IEvent[oldV.length+1];
System.arraycopy(oldV, 0, newV, 0, oldV.length);
newV[oldV.length]=ev;
events.put(time, newV);
} else {
events.put(time, new IEvent[] {ev});
}
events.put(ev.getTime(), ev);
}
protected abstract Map<Integer, ITx> getTransactions();

View File

@ -73,14 +73,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
* @param evt the evt
*/
public void addEvent(ITxEvent evt) {
if (!events.containsKey(evt.getTime()))
events.put(evt.getTime(), new IEvent[] { evt });
else {
IEvent[] evts = events.get(evt.getTime());
IEvent[] newEvts = Arrays.copyOf(evts, evts.length + 1);
newEvts[evts.length] = evt;
events.put(evt.getTime(), newEvts);
}
events.put(evt.getTime(), evt);
}
/**

View File

@ -67,15 +67,7 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
}
public void addSignalChange(Long time, T value){
if(values.containsKey(time)) {
IEvent[] oldV = values.get(time);
IEvent[] newV = new IEvent[oldV.length+1];
System.arraycopy(oldV, 0, newV, 0, oldV.length);
newV[oldV.length]=value;
values.put(time, newV);
} else {
values.put(time, new IEvent[] {value});
}
values.put(time, value);
}
@Override

View File

@ -1,5 +1,7 @@
package com.minres.scviewer.database;
import java.util.Arrays;
public class EventEntry implements Comparable<EventEntry>{
public long timestamp; // unsigned
public IEvent[] events = null;
@ -25,4 +27,15 @@ public class EventEntry implements Comparable<EventEntry>{
public String toString() {
return String.format("e.%d@%d", events.length,timestamp);
}
public void append(IEvent value) {
if(events.length==0)
events = new IEvent[] {value};
else {
int idx = events.length;
events = Arrays.copyOf(events, idx+1);
events[idx]=value;
}
}
}

View File

@ -1,6 +1,7 @@
package com.minres.scviewer.database;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@ -85,24 +86,23 @@ public class EventList implements IEventList {
}
@Override
public IEvent[] put(long key, IEvent[] value) {
public void put(long key, IEvent value) {
if(unmodifiable) throw new UnsupportedOperationException();
EventEntry e = new EventEntry(key, value);
if(store.size()==0 || store.get(store.size()-1).timestamp < key) {
store.add(e);
store.add(new EventEntry(key, new IEvent[] {value}));
} else {
int index = Collections.binarySearch(store, new EventEntry(key));
// < 0 if element is not in the list, see Collections.binarySearch
if (index < 0) {
EventEntry e = new EventEntry(key, new IEvent[] {value});
index = -(index + 1);
store.add(index, e);
} else {
// Insertion index is index of existing element, to add new element behind it increase index
store.set(index, e);
store.get(index).append(value);
}
}
end=store.size();
return e.events;
}
@Override

View File

@ -12,7 +12,7 @@ public interface IEventList extends Iterable<EventEntry> {
IEvent[] get(long key);
IEvent[] put(long key, IEvent[] value);
void put(long key, IEvent value);
long firstKey();

View File

@ -12,7 +12,6 @@ import java.util.stream.Collectors;
import org.junit.Test;
import com.minres.scviewer.database.EventList;
import com.minres.scviewer.database.IEvent;
import com.minres.scviewer.database.IEventList;
public class EventListTest {
@ -20,7 +19,7 @@ public class EventListTest {
EventList createList(int[] times) {
EventList list = new EventList();
for(int time: times)
list.put(time, new IEvent[] {});
list.put(time, null);
return list;
}