Lab 10 FAQ

Dijkstra’s and the graph visualizer

The visualizer opens but Compute shows nothing / an error

Compute constructs your Lab10DFS, Lab10BFS, or Lab10Dijkstras and reads the order off of it. If a method still returns null, or anything throws, the page reports that instead of an order. Implement the method (or fix the exception), then stop and re-run Main. Refreshing the page is not enough, since the running program still has your old code.

“Address already in use” when running a visualizer

An earlier run of Main is still serving on port 4567. Stop that run in IntelliJ and try again.

The browser didn’t open automatically

The program prints the URL it is serving at (for example http://localhost:4567/). Open that in any browser.

For Dijkstra’s: distTo is wrong for one node but the rest are right

Make sure you set distTo[v] and edgeTo[v] and call changePriority every time a relaxation succeeds. Missing any one of the three gives confusing, partly-correct results.

Can’t find Javalin

It comes from library-fa26. Make sure the library is attached to your IntelliJ project as described in the Assignment Workflow Guide.

Hashing (bonus)

-=-=-=-=- needs review -=-=-=-=-=-

TestSimpleOomage won’t compile after I uncommented a test

Make sure you uncommented the whole test, including the @Test line above the method and the closing }. If IntelliJ complains about HashSet or List, the imports are already at the top of the file, so that usually means a stray /* or */ is still hanging around.

testHashCodePerfect passes even with the simple red + green + blue hashCode

Then your test isn’t checking enough Oomages. Remember that the legal values are every multiple of 5 from 0 up to and including 255, so there are 52 choices for each of red, green, and blue. Loop over all of them and make sure you never see a repeated hash code.

Why Math.floorMod instead of %?

A hashCode can be negative, and in Java -7 % 10 is -7. Using % to pick a bucket would give you a negative index and an ArrayIndexOutOfBoundsException. Math.floorMod(-7, 10) is 3, and in general Math.floorMod(x, M) is always between 0 and M - 1.

Why not Math.abs(hashCode) % M?

Try Math.abs(Integer.MIN_VALUE) (that is, Math.abs(-2147483648)) and see what you get. Because of how 32-bit integers work, the result is still negative, so this approach has a rare but real bug.

Everything lands in two buckets in the visualizer

Your hashCode is probably always a multiple of 5. See Evaluating the perfect hashCode Visually in the spec.

My testWithDeadlyParams throws an IllegalArgumentException

Every number in a ComplexOomage’s list must be between 0 and 255 inclusive, and the list can’t be empty or null. The test should fail because of a bad spread, not because of a bad argument.

Hint.java prints 0 for the 4th power of 256. Is that a bug?

No. That’s integer overflow: 256⁴ = 2³², which needs 33 bits, and an int only has 32. See the “How Java Stores an int” detour in the spec, and think about what that means for ComplexOomage.hashCode.

Can’t find StdDraw or StdRandom

They come from library-fa26. Make sure the library is attached to your IntelliJ project as described in the Assignment Workflow Guide.

-=-=-=-=- needs review -=-=-=-=-=-