Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/main/ArrayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
MIT License

Copyright (c) 2019 w0rthy
Copyright (c) 2020 ArrayV 4.0 Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -39,23 +38,23 @@ final public class ArrayManager {
private int[] presortedArray;
private utils.Shuffles[] shuffleTypes;
private utils.Distributions[] distributionTypes;
private String[] shuffleIDs = {
private String[] shuffleIDs/* = {
"Randomly", "Backwards", "Slight Shuffle", "No Shuffle", "Sorted", "Reverse Sorted",
"Scrambled Tail", "Scrambled Head", "Noisy", "Scrambled Odds",
"Scrambled Tail", "Scrambled Head", "Noisy", "Shuffled Odds",
"Final Merge Pass", "Sawtooth", "Reversed Final Merge", "Reversed Sawtooth", "Pipe Organ", "Final Bitonic Pass",
"Interlaced", "Double Layered", "Final Radix", "Recursive Final Radix",
"Half Rotation", "Half Reversed", "BST Traversal", "Logarithmic Slopes",
"Heapified", "Reversed Poplarified", "First Circle Pass", "Final Pairwise Pass",
"Heapified", "Revered Poplarified", "First Circle Pass", "Final Pairwise Pass",
"Recursive Reversal", "Gray Code Fractal", "Sierpinski Triangle",
"Triangular"
};
private String[] distributionIDs = {
}*/;
private String[] distributionIDs/* = {
"Linear", "Few Unique", "Random",
"Quadratic", "Square Root", "Centered Cubic", "Centered Quintic",
"Perlin Noise", "Perlin Noise Curve", "Bell Curve",
"Ruler", "Blancmange Curve", "Cantor Function",
"Sum of Divisors", "Fly Straight, Damnit!", "Decreasing Random"
};
}*/;

private volatile boolean MUTABLE;

Expand All @@ -78,6 +77,14 @@ public ArrayManager(ArrayVisualizer arrayVisualizer) {
this.Delays = ArrayVisualizer.getDelays();
this.Highlights = ArrayVisualizer.getHighlights();
this.Writes = ArrayVisualizer.getWrites();

this.shuffleIDs = new String[this.shuffleTypes.length];
for (int i = 0; i < this.shuffleTypes.length; i++)
this.shuffleIDs[i] = this.shuffleTypes[i].getName();

this.distributionIDs = new String[this.distributionTypes.length];
for (int i = 0; i < this.distributionTypes.length; i++)
this.distributionIDs[i] = this.distributionTypes[i].getName();

this.MUTABLE = true;
}
Expand All @@ -93,13 +100,11 @@ public void toggleMutableLength(boolean Bool) {
public void initializeArray(int[] array) {
int currentLen = ArrayVisualizer.getCurrentLength();

int[] temp = new int[currentLen];
double uniqueFactor = (double)currentLen/ArrayVisualizer.getUniqueItems();
for(int i = 0; i < currentLen; i++)
temp[i] = (int)(uniqueFactor*(int)(i/uniqueFactor))+(int)uniqueFactor/2;
array[i] = (int)(uniqueFactor*(int)(i/uniqueFactor))+(int)uniqueFactor/2;

Distributions.initializeArray(temp, this.ArrayVisualizer);
System.arraycopy(temp, 0, array, 0, currentLen);
Distributions.initializeArray(array, this.ArrayVisualizer);
}

public void initializePresortedArray() {
Expand Down Expand Up @@ -184,4 +189,4 @@ public void refreshArray(int[] array, int currentLen, ArrayVisualizer ArrayVisua

ArrayVisualizer.resetAllStatistics();
}
}
}
133 changes: 102 additions & 31 deletions src/utils/Distributions.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package utils;

import java.util.Arrays;
import java.util.Random;

import main.ArrayVisualizer;

/*
Expand Down Expand Up @@ -33,39 +30,50 @@ of this software and associated documentation files (the "Software"), to deal

public enum Distributions {
LINEAR {
public String getName() {
return "Linear";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
}
},
SIMILAR {
public String getName() {
return "Few Unique";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Random random = new Random();

int l = 0, r, t = Math.min(currentLen, 8);
for(int i = 0; i < t; i++)
if(random.nextDouble() < 0.5) l++;
r = currentLen-(t-l);

int i = 0;
for(; i < l; i++) array[i] = (int) (currentLen * 0.25);
for(; i < r; i++) array[i] = currentLen / 2;
for(; i < currentLen; i++) array[i] = (int) (currentLen * 0.75);
int i;
for(i = 0; i < currentLen - 8; i++) {
array[i] = currentLen / 2;
}
for(; i < currentLen; i++) {
array[i] = (int) (Math.random() < 0.5 ? currentLen * 0.75 : currentLen * 0.25);
}
}
},
RANDOM {
public String getName() {
return "Random";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Random random = new Random();
int[] temp = new int[currentLen];

for(int i = 0; i < currentLen; i++)
temp[i] = array[(int)(Math.random()*currentLen)];

int[] temp = Arrays.copyOf(array, currentLen);
for(int i = 0; i < currentLen; i++)
array[i] = temp[random.nextInt(currentLen)];
array[i] = temp[i];
}
},
SQUARE {
public String getName() {
return "Quadratic";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Expand All @@ -75,6 +83,9 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
}
},
SQRT {
public String getName() {
return "Square Root";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Expand All @@ -84,6 +95,9 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
}
},
CUBIC {
public String getName() {
return "Centered Cubic";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Expand All @@ -95,6 +109,9 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
}
},
QUINTIC {
public String getName() {
return "Centered Quintic";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Expand All @@ -106,15 +123,17 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
}
},
PERLIN_NOISE {
public String getName() {
return "Perlin Noise";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Random random = new Random();

int[] perlinNoise = new int[currentLen];
int[] temp = new int[currentLen];

float step = 1f / currentLen;
float randomStart = (float) (random.nextInt(currentLen));
float randomStart = (float) (Math.random() * currentLen);
int octave = (int) (Math.log(currentLen) / Math.log(2));

for(int i = 0; i < currentLen; i++) {
Expand Down Expand Up @@ -147,25 +166,37 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
}
}

int[] temp = Arrays.copyOf(array, currentLen);
for(int i = 0; i < currentLen; i++) {
temp[i] = array[i];
}
for(int i = 0; i < currentLen; i++) {
array[i] = temp[Math.min(perlinNoise[i], currentLen-1)];
}
}
},
PERLIN_NOISE_CURVE {
public String getName() {
return "Perlin Noise Curve";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();

int[] temp = Arrays.copyOf(array, currentLen);
int[] temp = new int[currentLen];
for(int i = 0; i < currentLen; i++) {
temp[i] = array[i];
}

for(int i = 0; i < currentLen; i++) {
int value = 0 - (int) (PerlinNoise.returnNoise((float) array[i] / currentLen) * currentLen);
array[i] = temp[Math.min(value, currentLen-1)];
}
}
},
BELL_CURVE {
public String getName() {
return "Bell Curve";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Expand All @@ -174,7 +205,11 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int constant = 1264;
double factor = currentLen / 512d;

int[] temp = Arrays.copyOf(array, currentLen);
int[] temp = new int[currentLen];
for(int i = 0; i < currentLen; i++) {
temp[i] = array[i];
}

for(int i = 0; i < currentLen; i++) {
double square = Math.pow(position, 2);
double negativeSquare = 0 - square;
Expand All @@ -190,6 +225,9 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
}
},
RULER {
public String getName() {
return "Ruler";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Expand Down Expand Up @@ -221,12 +259,19 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
}
},
BLANCMANGE {
public String getName() {
return "Blancmange Curve";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
int floorLog2 = (int)(Math.log(currentLen)/Math.log(2));

int[] temp = Arrays.copyOf(array, currentLen);
int[] temp = new int[currentLen];
for(int i = 0; i < currentLen; i++) {
temp[i] = array[i];
}

for(int i = 0; i < currentLen; i++) {
int value = (int)(currentLen * curveSum(floorLog2, (double)i/currentLen));
array[i] = temp[value];
Expand All @@ -249,11 +294,17 @@ public double triangleWave(double x) {
}
},
CANTOR {
public String getName() {
return "Cantor Function";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();

int[] temp = Arrays.copyOf(array, currentLen);
int[] temp = new int[currentLen];
for(int i = 0; i < currentLen; i++) {
temp[i] = array[i];
}
cantor(array, temp, 0, currentLen, 0, currentLen-1);
}

Expand All @@ -276,10 +327,14 @@ public void cantor(int[] array, int[] temp, int a, int b, int min, int max) {
}
},
DIVISORS {//O(n^1.5)
public String getName() {
return "Sum of Divisors";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
int[] n = new int[currentLen];
int[] temp = new int[currentLen];

n[0] = 0;
n[1] = 1;
Expand All @@ -290,7 +345,10 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
if(n[i] > max) max = n[i];
}

int[] temp = Arrays.copyOf(array, currentLen);
for(int i = 0; i < currentLen; i++) {
temp[i] = array[i];
}

double scale = Math.min((currentLen-1)/max, 1);
for(int i = 0; i < currentLen; i++) {
array[i] = temp[(int)(n[i]*scale)];
Expand All @@ -309,10 +367,14 @@ public int sumDivisors(int n) {
}
},
FSD {// fly straight dangit (OEIS A133058)
public String getName() {
return "Fly Straight, Damnit!";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
int[] fsd = new int[currentLen];
int[] temp = new int[currentLen];

double max;
max = fsd[0] = fsd[1] = 1;
Expand All @@ -322,7 +384,9 @@ public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
if(fsd[i] > max) max = fsd[i];
}

int[] temp = Arrays.copyOf(array, currentLen);
for(int i = 0; i < currentLen; i++)
temp[i] = array[i];

double scale = Math.min((currentLen-1)/max, 1);
for(int i = 0; i < currentLen; i++)
array[i] = temp[(int)(fsd[i]*scale)];
Expand All @@ -334,18 +398,25 @@ public int gcd(int a, int b) {
}
},
REVLOG {
public String getName() {
return "Decreasing Random";
}
@Override
public void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer) {
int currentLen = ArrayVisualizer.getCurrentLength();
Random random = new Random();

int[] temp = Arrays.copyOf(array, currentLen);
int[] temp = new int[currentLen];
for(int i = 0; i < currentLen; i++) {
temp[i] = array[i];
}

for(int i = 0; i < currentLen; i++){
int r = random.nextInt(currentLen - i) + i;
array[i] = temp[r];
int random = (int) (Math.random() * (currentLen - i)) + i;
array[i] = temp[random];
}
}
};

public abstract String getName();
public abstract void initializeArray(int[] array, ArrayVisualizer ArrayVisualizer);
}
}
Loading