{"id":19989771,"url":"https://github.com/wcygan/java-practice","last_synced_at":"2025-03-01T21:52:33.093Z","repository":{"id":132525538,"uuid":"576116353","full_name":"wcygan/java-practice","owner":"wcygan","description":"java-practice","archived":false,"fork":false,"pushed_at":"2024-12-30T20:23:50.000Z","size":192,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-12T12:20:13.010Z","etag":null,"topics":["algorithms","concurrency","concurrent-data-structure","concurrent-programming","data-structures","java","jvm","property-based-testing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wcygan.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-09T03:29:35.000Z","updated_at":"2024-12-30T20:23:53.000Z","dependencies_parsed_at":"2024-12-30T21:28:24.963Z","dependency_job_id":"26e2681b-3db8-41e4-978f-aa1073650e26","html_url":"https://github.com/wcygan/java-practice","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcygan%2Fjava-practice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcygan%2Fjava-practice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcygan%2Fjava-practice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wcygan%2Fjava-practice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wcygan","download_url":"https://codeload.github.com/wcygan/java-practice/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241430318,"owners_count":19961635,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","concurrency","concurrent-data-structure","concurrent-programming","data-structures","java","jvm","property-based-testing"],"created_at":"2024-11-13T04:50:05.123Z","updated_at":"2025-03-01T21:52:33.066Z","avatar_url":"https://github.com/wcygan.png","language":"Java","readme":"# Practice\n\nPracticing Data Structures, Algorithms, Concurrency, and more in [Java](https://www.oracle.com/java/technologies/)!\n\n## Table of Contents\n\n- **[Cool Stuff](#cool-stuff)**\u003cbr\u003e\n    - **[Data Structures](#data-structures)**\u003cbr\u003e\n    - **[Algorithms](#algorithms)**\u003cbr\u003e\n- **[Build and Run](#build-and-run)**\u003cbr\u003e\n- **[Property-Based Testing with JUnit-Quickcheck](#property-based-testing-with-junit-quickcheck)**\u003cbr\u003e\n- **[References](#references)**\u003cbr\u003e\n\n## Cool Stuff\n\n### Data Structures\n\n1. [LRU Cache](src/main/java/io/wcygan/collections/cache/LRUCache.java)\n2. [Red Black Tree](src/main/java/io/wcygan/collections/tree/LLRedBlackTree.java)\n3. [Disjoint Set](src/main/java/io/wcygan/collections/set/DisjointSet.java)\n4. [D-Way Heap](src/main/java/io/wcygan/collections/queue/DWayHeap.java)\n5. [Graph](src/main/java/io/wcygan/collections/graph/SimpleGraph.java)\n6. [ArrayBlockingQueue](src/main/java/io/wcygan/concurrent/collections/queue/ArrayBlockingQueue.java)\n7. [Non-blocking Queue](src/main/java/io/wcygan/concurrent/collections/queue/NonblockingQueue.java)\n8. [Non-blocking Stack](src/main/java/io/wcygan/concurrent/collections/stack/NonblockingStack.java)\n9. [Thread-ID based Lock](src/main/java/io/wcygan/concurrent/locks/TIDLock.java)\n\n### Algorithms\n\n1. [Quick Sort](src/main/java/io/wcygan/algorithms/sorting/QuickSort.java)\n2. [Merge Sort](src/main/java/io/wcygan/algorithms/sorting/MergeSort.java)\n3. [Parallel Merge Sort](src/main/java/io/wcygan/algorithms/sorting/ParallelMergeSort.java)\n4. [Shortest Path](src/main/java/io/wcygan/algorithms/graph/pathfinding/ShortestPath.java) (Graph)\n5. [Breadth-First Search](src/main/java/io/wcygan/algorithms/graph/traversal/BreadthFirstSearch.java) (Graph)\n6. [Depth-First Search](src/main/java/io/wcygan/algorithms/graph/traversal/DepthFirstSearch.java) (Graph)\n\n## Benchmarking\n\nUsing [jmh](https://github.com/openjdk/jmh) you are able to benchmark java code.\n\nTo execute the benchmarks in `src/jmh`, run the following command:\n\n```\n$ gradle jmh\n```\n\nFor example, you can see this in action in\n[CacheLinesBenchmark.java](src/jmh/java/io/wcygan/algorithms/gotchas/CacheLinesBenchmark.java) where we obtain the\nfollowing results:\n\n```\n(Run on 2021 M1 Max Macbook Pro)\nBenchmark                                          Mode  Cnt  Score   Error  Units\ni.w.a.gotchas.CacheLinesBenchmark.touchEveryItem       ss  100   0.167 ± 0.002  ms/op\ni.w.a.gotchas.CacheLinesBenchmark.touchEveryLine       ss  100   0.136 ± 0.007  ms/op\n```\n\nAnother example is [SortingBenchmark.java](src/jmh/java/io/wcygan/algorithms/sorting/SortingBenchmark.java) where we\ncompare the benchmark running time of different sorting algorithms:\n\n```\nBenchmark                                            Mode  Cnt   Score   Error  Units\ni.w.a.sorting.SortingBenchmark.classicSort             ss  100  12.142 ± 0.081  ms/op\ni.w.a.sorting.SortingBenchmark.heapsort                ss  100  13.768 ± 0.073  ms/op\ni.w.a.sorting.SortingBenchmark.mergesort               ss  100  16.790 ± 0.112  ms/op\ni.w.a.sorting.SortingBenchmark.parallelMergesort       ss  100  17.958 ± 0.835  ms/op\ni.w.a.sorting.SortingBenchmark.parallelStandardSort    ss  100   2.338 ± 0.091  ms/op\ni.w.a.sorting.SortingBenchmark.quicksort               ss  100  12.859 ± 0.088  ms/op\ni.w.a.sorting.SortingBenchmark.standardSort            ss  100  13.733 ± 0.061  ms/op\n\n```\n\n## Build and Run\n\nThis project uses [Gradle](https://gradle.org/install/). Make sure that you\nhave [Java](https://java.com/en/download/help/download_options.html) installed.\n\nTo run the entire suite of tests:\n\n```\n$ ./gradlew test\n```\n\nTo run a specific test class:\n\n```\n$ ./gradlew test --tests \u003cTestClassName\u003e\n```\n\nFor example, I can run the tests\nat [WeightedShortestPathTest](src/test/java/io/wcygan/algorithms/graph/pathfinding/WeightedShortestPathTest.java)\nwith:\n\n```\n$ ./gradlew test --tests WeightedShortestPathTest\n```\n\nFurther, we can a **single** test by specifying its fully qualified path like so:\n\n```\n$ ./gradlew test --tests io.wcygan.algorithms.graph.pathfinding.WeightedShortestPathTest.testWeightedShortestPath\n```\n\n### Building a jar file\n\nBuilds a jar containing **all dependencies** of the project\n\n```\n$ ./gradlew shadowJar\n```\n\nBuilds a jar containing **only the application classes** from the project\n\n```\n$ ./gradlew jar\n```\n\n## Property-Based Testing with JUnit-Quickcheck\n\nProperty-Based Testing allows you to test the programs you write by feeding a program randomly generated inputs.\nSee [Getting Started with JUnit-Quickcheck](https://pholser.github.io/junit-quickcheck/site/1.0/usage/getting-started.html)\nfor more details.\n\nOnce you've written a property-based test (like\n[SortingQuickCheck](src/test/java/io/wcygan/algorithms/sorting/SortingQuickCheckTest.java))\nyou can execute it in isolation just as we did before:\n\n```\n$ ./gradlew test --tests io.wcygan.algorithms.sorting.SortingQuickCheckTest.testSortingAlgorithms\n```\n\nYou can configure the execution of your property-based test using the elements of\nthe [@Property annotation](https://pholser.github.io/junit-quickcheck/site/1.0/junit-quickcheck-core/apidocs/com/pholser/junit/quickcheck/Property.html)\n. For example, you can write `@Property(trials = 10)` to have the test execute 10 times.\n\n## References\n\nI'm using the following material as a reference:\n\n1. [Introduction to Algorithms](https://mitpress.mit.edu/books/introduction-algorithms-third-edition)\n2. [Java Concurrency in Practice](https://jcip.net/)\n3. [The Art of Multiprocessor Programming](https://www.oreilly.com/library/view/the-art-of/9780123705914/)\n4. [Effective Java](https://www.oreilly.com/library/view/effective-java/9780134686097/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwcygan%2Fjava-practice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwcygan%2Fjava-practice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwcygan%2Fjava-practice/lists"}