Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lab_bins
First example code for refactoring

I LOVE CATS YAYYY!
Making a change!!!

Even more changes :)
Expand Down
58 changes: 25 additions & 33 deletions src/Bins.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,37 @@ public static void main (String args[]) {
PriorityQueue<Disk> pq = new PriorityQueue<Disk>();
pq.add(new Disk(0));

int diskId = 1;
int total = 0;
for (Integer size : data) {
Disk d = pq.peek();
if (d.freeSpace() > size) {
pq.poll();
d.add(size);
pq.add(d);
} else {
Disk d2 = new Disk(diskId);
diskId++;
d2.add(size);
pq.add(d2);
}
total += size;
}

total = addToDisk(total, pq, data);

System.out.println("total size = " + total / 1000000.0 + "GB");
System.out.println();
System.out.println("worst-fit method");
System.out.println("number of pq used: " + pq.size());
while (!pq.isEmpty()) {
System.out.println(pq.poll());
}
System.out.println();

printQueue(pq, "");

Collections.sort(data, Collections.reverseOrder());
pq.add(new Disk(0));

diskId = 1;
for (Integer size : data) {
total = addToDisk( total, pq, data);

System.out.println();

printQueue(pq,"decreasing ");
}
public static void printQueue(PriorityQueue<Disk> pq, String word) {
System.out.println();
System.out.println("worst-fit " + word + "method");
System.out.println("number of pq used: " + pq.size());
while (!pq.isEmpty()) {
System.out.println(pq.poll());
}
System.out.println();
}
public static int addToDisk(int total, PriorityQueue<Disk> pq, List<Integer> data) {
int diskId = 1;
for (Integer size : data) {
Disk d = pq.peek();
if (d.freeSpace() >= size) {
if (d.freeSpace() >= size) { //one has = one does not, don't know how to fix
pq.poll();
d.add(size);
pq.add(d);
Expand All @@ -79,14 +77,8 @@ public static void main (String args[]) {
d2.add(size);
pq.add(d2);
}
total += size;
}

System.out.println();
System.out.println("worst-fit decreasing method");
System.out.println("number of pq used: " + pq.size());
while (!pq.isEmpty()) {
System.out.println(pq.poll());
}
System.out.println();
return total;
}
}