u13
This commit is contained in:
parent
4b7f4dfd52
commit
81ee8d3152
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="lib" path="/home/stud/p8q-yhw-u1/Downloads/libzarr.jar"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
|
@ -0,0 +1 @@
|
||||||
|
/bin/
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>u13</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,14 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=17
|
||||||
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=17
|
|
@ -0,0 +1,18 @@
|
||||||
|
package de.hsh.zahlenarraytest;
|
||||||
|
|
||||||
|
import de.hsh.prog.zahlenarray.ZahlenPruefer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main-Klasse zum Testen der zarr Klassen
|
||||||
|
* @author p8q-yhw-u1
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
MeinZahlenarray array= new MeinZahlenarray(10000, 500000);
|
||||||
|
int anzahl= ZahlenPruefer.anzahlVerschiedene(array);
|
||||||
|
System.out.println("Anzahl: "+anzahl);
|
||||||
|
System.out.println("istEnthalten verbraucht durchschnittlich "
|
||||||
|
+1000*array.getDurchschnittlicheAbfragezeit()+" µs");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package de.hsh.zahlenarraytest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import de.hsh.prog.zahlenarray.Zahlenarray;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verbesserung der Zahlenarray Klasse für Zeitmessung und Optimierung
|
||||||
|
* @author p8q-yhw-u1
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class MeinZahlenarray extends Zahlenarray {
|
||||||
|
|
||||||
|
private Zeitmesser zm;
|
||||||
|
private int[] zahlen;
|
||||||
|
|
||||||
|
private int abfragen;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialisiert ein sortiertes Zahlenarray
|
||||||
|
* @param anzahl Größe des Arrays
|
||||||
|
* @param max Obergrenze der Zufallszahlen mit denen das Array gefüllt wird
|
||||||
|
*/
|
||||||
|
public MeinZahlenarray(int anzahl, int max) {
|
||||||
|
super(anzahl, max);
|
||||||
|
|
||||||
|
this.zm = new Zeitmesser();
|
||||||
|
|
||||||
|
this.zahlen = super.getZahlenArray();
|
||||||
|
|
||||||
|
zm.start();
|
||||||
|
Arrays.sort(zahlen);
|
||||||
|
zm.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt zurück, ob eine Zahl i mindestens einmal im Array vorhanden ist
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean istEnthalten(int i) {
|
||||||
|
this.zm.start();
|
||||||
|
boolean result = Arrays.binarySearch(zahlen, i) >= 0;
|
||||||
|
this.zm.stop();
|
||||||
|
|
||||||
|
this.abfragen++;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die durchschnittliche Abfragezeit der istEnthalten Funktion zurück
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public double getDurchschnittlicheAbfragezeit() {
|
||||||
|
return (double) this.zm.getGemesseneGesamtzeit() / this.abfragen;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package de.hsh.zahlenarraytest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Klasse zum Messen von Zeit in Milisekunden
|
||||||
|
* @author p8q-yhw-u1
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Zeitmesser {
|
||||||
|
|
||||||
|
private boolean running = false;
|
||||||
|
|
||||||
|
private long startTime;
|
||||||
|
private long sumTime = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Startet eine Zeitmessung
|
||||||
|
*/
|
||||||
|
public void start() {
|
||||||
|
if (this.running) throw new IllegalStateException("Zeitmessung läuft bereits.");
|
||||||
|
|
||||||
|
this.running = true;
|
||||||
|
this.startTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Beendet eine Zeitmessung
|
||||||
|
*/
|
||||||
|
public void stop() {
|
||||||
|
if (! this.running) throw new IllegalStateException("Zeitmessung bereits gestoppt.");
|
||||||
|
|
||||||
|
this.running = false;
|
||||||
|
this.sumTime += System.currentTimeMillis() - this.startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Liefert die Summe aller beendeten Zeitmessungen
|
||||||
|
* @return Summe aller beendeten Zeitmessungen
|
||||||
|
*/
|
||||||
|
public long getGemesseneGesamtzeit() {
|
||||||
|
if (this.running) throw new IllegalStateException("Zeitmessung läuft noch.");
|
||||||
|
return this.sumTime;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue