some more refactoring

This commit is contained in:
Eyck Jentzsch 2021-02-27 13:47:37 +00:00
parent 5df91dbaa8
commit b7301733f0
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){ private void putEvent(TxEvent ev){
Long time = ev.getTime(); events.put(ev.getTime(), ev);
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});
}
} }
protected abstract Map<Integer, ITx> getTransactions(); protected abstract Map<Integer, ITx> getTransactions();

View File

@ -73,14 +73,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
* @param evt the evt * @param evt the evt
*/ */
public void addEvent(ITxEvent evt) { public void addEvent(ITxEvent evt) {
if (!events.containsKey(evt.getTime())) events.put(evt.getTime(), evt);
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);
}
} }
/** /**

View File

@ -67,15 +67,7 @@ public class VCDSignal<T extends IEvent> extends HierNode implements IWaveform {
} }
public void addSignalChange(Long time, T value){ public void addSignalChange(Long time, T value){
if(values.containsKey(time)) { values.put(time, value);
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});
}
} }
@Override @Override

View File

@ -1,5 +1,7 @@
package com.minres.scviewer.database; package com.minres.scviewer.database;
import java.util.Arrays;
public class EventEntry implements Comparable<EventEntry>{ public class EventEntry implements Comparable<EventEntry>{
public long timestamp; // unsigned public long timestamp; // unsigned
public IEvent[] events = null; public IEvent[] events = null;
@ -25,4 +27,15 @@ public class EventEntry implements Comparable<EventEntry>{
public String toString() { public String toString() {
return String.format("e.%d@%d", events.length,timestamp); 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; package com.minres.scviewer.database;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -85,24 +86,23 @@ public class EventList implements IEventList {
} }
@Override @Override
public IEvent[] put(long key, IEvent[] value) { public void put(long key, IEvent value) {
if(unmodifiable) throw new UnsupportedOperationException(); if(unmodifiable) throw new UnsupportedOperationException();
EventEntry e = new EventEntry(key, value);
if(store.size()==0 || store.get(store.size()-1).timestamp < key) { if(store.size()==0 || store.get(store.size()-1).timestamp < key) {
store.add(e); store.add(new EventEntry(key, new IEvent[] {value}));
} else { } else {
int index = Collections.binarySearch(store, new EventEntry(key)); int index = Collections.binarySearch(store, new EventEntry(key));
// < 0 if element is not in the list, see Collections.binarySearch // < 0 if element is not in the list, see Collections.binarySearch
if (index < 0) { if (index < 0) {
EventEntry e = new EventEntry(key, new IEvent[] {value});
index = -(index + 1); index = -(index + 1);
store.add(index, e); store.add(index, e);
} else { } else {
// Insertion index is index of existing element, to add new element behind it increase index // 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(); end=store.size();
return e.events;
} }
@Override @Override

View File

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

View File

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