diff --git a/.github/workflows/update_directory_md.yml b/.github/workflows/update_directory_md.yml deleted file mode 100644 index 019b478b3..000000000 --- a/.github/workflows/update_directory_md.yml +++ /dev/null @@ -1,67 +0,0 @@ -# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push -name: update_directory_md -on: [push] -jobs: - update_directory_md: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - uses: actions/setup-python@master - - name: update_directory_md - shell: python - run: | - import os - from typing import Iterator - - URL_BASE = "https://github.com/TheAlgorithms/Go/blob/master" - g_output = [] - - - def good_filepaths(top_dir: str = ".") -> Iterator[str]: - for dirpath, dirnames, filenames in os.walk(top_dir): - dirnames[:] = [d for d in dirnames if d[0] not in "._"] - for filename in filenames: - if os.path.splitext(filename)[1].lower() == ".go": - yield os.path.join(dirpath, filename).lstrip("./") - - - def md_prefix(i): - return f"{i * ' '}*" if i else "\n##" - - - def print_path(old_path: str, new_path: str) -> str: - global g_output - old_parts = old_path.split(os.sep) - for i, new_part in enumerate(new_path.split(os.sep)): - if i + 1 > len(old_parts) or old_parts[i] != new_part: - if new_part: - g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}") - return new_path - - - def build_directory_md(top_dir: str = ".") -> str: - global g_output - old_path = "" - for filepath in sorted(good_filepaths(), key=str.lower): - filepath, filename = os.path.split(filepath) - if filepath != old_path: - old_path = print_path(old_path, filepath) - indent = (filepath.count(os.sep) + 1) if filepath else 0 - url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20") - filename = os.path.splitext(filename.replace("_", " ").title())[0] - g_output.append(f"{md_prefix(indent)} [{filename}]({url})") - return "\n".join(g_output) - - - with open("DIRECTORY.md", "w") as out_file: - out_file.write(build_directory_md(".") + "\n") - - - name: Update DIRECTORY.md - run: | - cat DIRECTORY.md - git config --global user.name github-actions - git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - git add DIRECTORY.md - git commit -am "updating DIRECTORY.md" || true - git push --force origin HEAD:$GITHUB_REF || true diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2771be750..feaaeb162 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,13 +15,13 @@ Welcome to [TheAlgorithms/Go](https://github.com/TheAlgorithms/Go)! Before submi Being a contributor at The Algorithms, we request you to follow the points mentioned below: - You did your own work. - - No plagiarism allowed. Any plagiarized work will not be merged. + - No plagiarism is allowed. Any plagiarized work will not be merged. - Your work will be distributed under the [MIT License](https://github.com/TheAlgoritms/Go/blob/master/LICENSE) once your pull request has been merged. - Please follow the repository guidelines and standards mentioned below. **New implementation** New implementations are welcome! -You can add new algorithms or data structures which are **not present in the repository** or that can **improve** the old implementations (**documentation**, **improving test cases**, removing bugs or in any other resonable sense) +You can add new algorithms or data structures that are **not present in the repository** or that can **improve** the old implementations (**documentation**, **improving test cases**, removing bugs, or in any other reasonable sense) **Issues** Please avoid opening issues asking to be "assigned” to a particular algorithm. This merely creates unnecessary noise for maintainers. Instead, please submit your implementation in a pull request, and it will be evaluated by project maintainers. @@ -33,7 +33,7 @@ You can add new algorithms or data structures which are **not present in the rep - Make sure the file extensions should be `*.go`. - Use meaning variable names. - Use standard library inside your code and avoid to import packages from other repositories -- If an implementation of the algorithm already exists, please refer to the [file-name section below](#new-file-name-guidelines). +- If an implementation of the algorithm already exists, please refer to the [filename section below](#new-file-name-guidelines). - You can suggest reasonable changes to existing algorithms. - Strictly use snake_case (underscore_separated) in filenames. - If you have added or modified code, please make sure the code compiles before submitting. @@ -55,6 +55,13 @@ You can add new algorithms or data structures which are **not present in the rep - If you find an algorithm or document without tests, please feel free to create a pull request or issue describing suggested changes. - Please try to add one or more `Test` functions that will invoke the algorithm implementation on random test data with the expected output. +### Benchmark + +- Make sure to add examples and benchmark cases in your `filename_test.go` or `filename_bench.go` if you want separated test and benchmark files. +- If you find an algorithm or document without benchmarks, please feel free to create a pull request or issue describing suggested changes. +- Please try to add one or more `Benchmark` functions that will invoke the algorithm implementation. +- For running the benchmark, you could use this command `go test -bench=.` for more details, read this article [Using Subtests and Sub-benchmarks](https://go.dev/blog/subtests) + #### Typical structure of a program ```go @@ -66,8 +73,9 @@ You can add new algorithms or data structures which are **not present in the rep // description containing links, references, // math equations, etc. // author(s) [Name](https://github.com/handle), [Name](https://github.com/handle) -// see related_file.go, another_file.go, file_test.go +// see relatedfile.go, anotherfile.go, file_test.go +// ** Is just an example of how to write description for package and function and other stuff ... ** // Package sort provides primitives for sorting slices and user-defined // collections. @@ -78,13 +86,13 @@ package sort // name2 package : Add one line description here // ... import ( - ... + ... ) // Fprint formats using the default formats for its operands and writes to w. // Spaces are added between operands when neither is a string. -// It returns the number of bytes written and any write error encountered. +// It returns the number of bytes written, and any write error encountered. func Fprint(w io.Writer, a ...interface{}) (n int, err error) { ... } @@ -94,17 +102,21 @@ func Fprint(w io.Writer, a ...interface{}) (n int, err error) { #### New File Name guidelines -- Use lowercase words with ``"_"`` as a separator +- Use lowercase words without ``"_"`` for the file name +- Use ``"_"`` as a separator only for `_test.go` or `_bench.go` - For instance ```markdown MyNewGoFile.GO is incorrect -my_new_go_file.go is correct format +my_new_go_file.go is incorrect +mynewgofile.go is the correct format +mynewgofile_test.go is the correct format ``` - It will be used to dynamically create a directory of files and implementation. - File name validation will run on Docker to ensure validity. -- If an implementation of the algorithm already exists and your version is different from that implemented, please use incremental numeric digit as a suffix. For example: if `binary_search.go` already exists in the `search` folder, and you are contributing a new implementation, the filename should be `binary_search2.go` and for a third implementation, `binary_search3.go`. +- If an implementation of the algorithm already exists and your version is different from that implemented, please use incremental numeric digit as a suffix. For example: if `binarysearch.go` already exists in the `search` folder, and you are contributing a new implementation, the filename should be `binarysearch2.go` and for a third implementation, `binarysearch3.go`. +- Check out `Go` [Package names](https://go.dev/blog/package-names) roles #### New Directory guidelines @@ -125,17 +137,17 @@ some_new_fancy_category is correct - It is recommended to keep your changes grouped logically within individual commits. Maintainers find it easier to understand changes that are logically spilled across multiple commits. Try to modify just one or two files in the same directory. Pull requests that span multiple directories are often rejected. ```bash -git add file_xyz.go +git add filexyz.go git commit -m "your message" ``` Examples of commit messages with semantic prefixes: ```markdown -fix: xyz algorithm bug -feat: add xyx algorithm -test: add test for xyz algorithm -docs: add comments and explanation to xyz algorithm +fix: XYZ algorithm bug +feat: add XYZ algorithm +test: add test for XYZ algorithm +docs: add comments and explanation to XYZ algorithm ``` Common prefixes: @@ -147,7 +159,7 @@ Common prefixes: ### Pull Requests -- Checkout our [pull request template](https://github.com/TheAlgorithms/Go/blob/master/.github/PULL_REQUEST_TEMPLATE/pull_request.md +- Check out our [pull request template](https://github.com/TheAlgorithms/Go/blob/master/.github/PULL_REQUEST_TEMPLATE/pull_request.md ) #### Building Locally @@ -162,9 +174,9 @@ go build . #### Code Formatter - Installation (only needs to be installed once.) - - Mac (using home-brew): `brew install go` - - Windows (MSYS2 64-bit): `choco install golang` [Chocolatey Package Manager](https://chocolatey.org/) - - Linux (Debian): `sudo apt-get install golang` + - Mac (using home-brew): `brew install go` + - Windows (MSYS2 64-bit): `choco install golang` [Chocolatey Package Manager](https://chocolatey.org/) + - Linux (Debian): `sudo apt-get install golang` - Running (all platforms): `go run main.go` or `go build main.go` #### GitHub Actions diff --git a/DIRECTORY.md b/DIRECTORY.md deleted file mode 100644 index 17854bf51..000000000 --- a/DIRECTORY.md +++ /dev/null @@ -1,192 +0,0 @@ - -## Ciphers - * Caesar - * [Caesar Cipher](https://github.com/TheAlgorithms/Go/blob/master/ciphers/caesar/caesar_cipher.go) - * [Caesar Test](https://github.com/TheAlgorithms/Go/blob/master/ciphers/caesar/caesar_test.go) - * Diffie Hellman Key Exchange - * [Diffie Hellman Key Exchange](https://github.com/TheAlgorithms/Go/blob/master/ciphers/diffie_hellman_key_exchange/diffie_hellman_key_exchange.go) - * [Diffie Hellman Key Exchange Test](https://github.com/TheAlgorithms/Go/blob/master/ciphers/diffie_hellman_key_exchange/diffie_hellman_key_exchange_test.go) - * Polybius - * [Polybius](https://github.com/TheAlgorithms/Go/blob/master/ciphers/polybius/polybius.go) - * [Polybius Test](https://github.com/TheAlgorithms/Go/blob/master/ciphers/polybius/polybius_test.go) - * Rot13 - * [Rot13](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rot13/rot13.go) - * [Rot13 Test](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rot13/rot13_test.go) - * Rsa Cipher - * [Rsa Cipher](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rsa_cipher/rsa_cipher.go) - * [Rsa Cipher Test](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rsa_cipher/rsa_cipher_test.go) - * Rsa Cipher Big - * [Rsa Cipher Big](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rsa_cipher_big/rsa_cipher_big.go) - * [Rsa Cipher Big Test](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rsa_cipher_big/rsa_cipher_big_test.go) - * Xor Cipher - * [Xor Cipher](https://github.com/TheAlgorithms/Go/blob/master/ciphers/xor_cipher/xor_cipher.go) - * [Xor Cipher Test](https://github.com/TheAlgorithms/Go/blob/master/ciphers/xor_cipher/xor_cipher_test.go) - -## Conversions - * Roman To Integer - * [Roman To Integer](https://github.com/TheAlgorithms/Go/blob/master/conversions/roman_to_integer/roman_to_integer.go) - * [Roman To Integer Test](https://github.com/TheAlgorithms/Go/blob/master/conversions/roman_to_integer/roman_to_integer_test.go) - -## Data Structures - * Binary Tree - * [Binary Search Tree](https://github.com/TheAlgorithms/Go/blob/master/data_structures/binary_tree/binary_search_tree.go) - * [Binary Tree](https://github.com/TheAlgorithms/Go/blob/master/data_structures/binary_tree/binary_tree.go) - * [Btree](https://github.com/TheAlgorithms/Go/blob/master/data_structures/binary_tree/btree.go) - * [Node](https://github.com/TheAlgorithms/Go/blob/master/data_structures/binary_tree/node.go) - * Dynamic Array - * [Dynamic Array](https://github.com/TheAlgorithms/Go/blob/master/data_structures/dynamic_array/dynamic_array.go) - * [Dynamic Array Test](https://github.com/TheAlgorithms/Go/blob/master/data_structures/dynamic_array/dynamic_array_test.go) - * Hashmap - * [Hashmap](https://github.com/TheAlgorithms/Go/blob/master/data_structures/hashmap/hashmap.go) - * [Hashmap Test](https://github.com/TheAlgorithms/Go/blob/master/data_structures/hashmap/hashmap_test.go) - * Linkedlist - * Doubly Linkedlist - * [Doubly Linkedlist](https://github.com/TheAlgorithms/Go/blob/master/data_structures/linkedlist/doubly_linkedlist/doubly_linkedlist.go) - * [Doubly Linkedlist Test](https://github.com/TheAlgorithms/Go/blob/master/data_structures/linkedlist/doubly_linkedlist/doubly_linkedlist_test.go) - * Singly Linkedlist - * [Singly Linkedlist](https://github.com/TheAlgorithms/Go/blob/master/data_structures/linkedlist/singly_linkedlist/singly_linkedlist.go) - * [Singly Linkedlist2](https://github.com/TheAlgorithms/Go/blob/master/data_structures/linkedlist/singly_linkedlist/singly_linkedlist2.go) - * [Singly Linkedlist Test](https://github.com/TheAlgorithms/Go/blob/master/data_structures/linkedlist/singly_linkedlist/singly_linkedlist_test.go) - * Trie - * [Trie](https://github.com/TheAlgorithms/Go/blob/master/data_structures/trie/trie.go) - * [Trie Test](https://github.com/TheAlgorithms/Go/blob/master/data_structures/trie/trie_test.go) - -## Design Patterns - * Abstract Factory - * [Abstract Factory Test](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/abstract_factory_test.go) - * [Adidas](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/adidas.go) - * [Adidas Shoe](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/adidas_shoe.go) - * [Adidasshirt](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/adidasshirt.go) - * [I Shirt](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/i_shirt.go) - * [I Shoe](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/i_shoe.go) - * [I Sports Factory](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/i_sports_factory.go) - * [Nike](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/nike.go) - * [Nike Shirt](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/nike_shirt.go) - * [Nike Shoe](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/nike_shoe.go) - * Builder - * [Builder Interface](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/builder/builder_interface.go) - * [Builder Pattern Test](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/builder/builder_pattern_test.go) - * [Director](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/builder/director.go) - * [House](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/builder/house.go) - * [Igloo Builder](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/builder/igloo_builder.go) - * [Normal Builder](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/builder/normal_builder.go) - * Factory Method - * [Accounting Department](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/factory_method/accounting_department.go) - * [Department](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/factory_method/department.go) - * [Department Factory](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/factory_method/department_factory.go) - * [Factory Method Test](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/factory_method/factory_method_test.go) - * [Finance Department](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/factory_method/finance_department.go) - * [I Department](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/factory_method/i_department.go) - * Prototype - * [File](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/prototype/file.go) - * [Folder](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/prototype/folder.go) - * [Node Interface](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/prototype/node_interface.go) - * [Prototype Test](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/prototype/prototype_test.go) - -## Dynamic Programming - * [Binomial Coefficient](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/binomial_coefficient.go) - * [Fibonacci](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/fibonacci.go) - * [Fibonacci Test](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/fibonacci_test.go) - * [Knapsack](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/knapsack.go) - * [Longest Common Subsequence](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/longest_common_subsequence.go) - * [Longest Palindromic Subsequence](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/longest_palindromic_subsequence.go) - * [Matrix Multiplication](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/matrix_multiplication.go) - * [Rod Cutting](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/rod_cutting.go) - -## Genetic Algorithm - * [Genetic Algo](https://github.com/TheAlgorithms/Go/blob/master/genetic_algorithm/genetic_algo.go) - -## Graphs - * Depth First Search - * [Depth First Search](https://github.com/TheAlgorithms/Go/blob/master/graphs/depth_first_search/depth_first_search.go) - * Floyd Warshall - * [Floyd Warshall](https://github.com/TheAlgorithms/Go/blob/master/graphs/floyd_warshall/floyd_warshall.go) - * Search - * [Breadth First Search](https://github.com/TheAlgorithms/Go/blob/master/graphs/search/breadth_first_search.go) - * [Breadth First Search Test](https://github.com/TheAlgorithms/Go/blob/master/graphs/search/breadth_first_search_test.go) - -## Math - * Gcd - * [Gcd](https://github.com/TheAlgorithms/Go/blob/master/math/gcd/gcd.go) - * [Gcd Iterative](https://github.com/TheAlgorithms/Go/blob/master/math/gcd/gcd_iterative.go) - * [Gcd Test](https://github.com/TheAlgorithms/Go/blob/master/math/gcd/gcd_test.go) - * Lcm - * [Lcm](https://github.com/TheAlgorithms/Go/blob/master/math/lcm/lcm.go) - * Modular Arithmetic - * [Modular Exponentiation](https://github.com/TheAlgorithms/Go/blob/master/math/modular_arithmetic/modular_exponentiation.go) - * [Modular Exponentiation Test](https://github.com/TheAlgorithms/Go/blob/master/math/modular_arithmetic/modular_exponentiation_test.go) - * Permutation - * [Heaps](https://github.com/TheAlgorithms/Go/blob/master/math/permutation/heaps.go) - * [Heaps Test](https://github.com/TheAlgorithms/Go/blob/master/math/permutation/heaps_test.go) - * Power - * [Fast Exponent](https://github.com/TheAlgorithms/Go/blob/master/math/power/fast_exponent.go) - * [Fast Exponent Test](https://github.com/TheAlgorithms/Go/blob/master/math/power/fast_exponent_test.go) - * Prime - * [Miller Rabin Primality Test](https://github.com/TheAlgorithms/Go/blob/master/math/prime/miller_rabin_primality_test.go) - * [Prime Check](https://github.com/TheAlgorithms/Go/blob/master/math/prime/prime_check.go) - * [Prime Test](https://github.com/TheAlgorithms/Go/blob/master/math/prime/prime_test.go) - * Pythagoras - * [Pythagoras](https://github.com/TheAlgorithms/Go/blob/master/math/pythagoras/pythagoras.go) - * [Pythagoras Test](https://github.com/TheAlgorithms/Go/blob/master/math/pythagoras/pythagoras_test.go) - * Sieve - * [Sieve](https://github.com/TheAlgorithms/Go/blob/master/math/sieve/sieve.go) - * [Sieve Test](https://github.com/TheAlgorithms/Go/blob/master/math/sieve/sieve_test.go) - -## Other - * Max Subarray Sum - * [Max Subarray Sum](https://github.com/TheAlgorithms/Go/blob/master/other/max_subarray_sum/max_subarray_sum.go) - * Monte Carlo Pi - * [Monte Carlo Pi](https://github.com/TheAlgorithms/Go/blob/master/other/monte_carlo_pi/monte_carlo_pi.go) - * [Monte Carlo Pi Test](https://github.com/TheAlgorithms/Go/blob/master/other/monte_carlo_pi/monte_carlo_pi_test.go) - * Nested Brackets - * [Nested Brackets](https://github.com/TheAlgorithms/Go/blob/master/other/nested_brackets/nested_brackets.go) - * Password Generator - * [Password Generator](https://github.com/TheAlgorithms/Go/blob/master/other/password_generator/password_generator.go) - * String Combinations - * [String Combinations](https://github.com/TheAlgorithms/Go/blob/master/other/string_combinations/string_combinations.go) - -## Searches - * [Binary Search](https://github.com/TheAlgorithms/Go/blob/master/searches/binary_search.go) - * [Linear Search](https://github.com/TheAlgorithms/Go/blob/master/searches/linear_search.go) - * [Search Test](https://github.com/TheAlgorithms/Go/blob/master/searches/search_test.go) - -## Set - * [Set](https://github.com/TheAlgorithms/Go/blob/master/set/set.go) - -## Sorts - * [Bubble Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubble_sort.go) - * [Heap Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/heap_sort.go) - * [Insertion Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/insertion_sort.go) - * [Merge Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/merge_sort.go) - * [Quick Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/quick_sort.go) - * [Radix Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/radix_sort.go) - * [Selection Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/selection_sort.go) - * [Shell Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/shell_sort.go) - * [Sorts Test](https://github.com/TheAlgorithms/Go/blob/master/sorts/sorts_test.go) - * [Sorts Testcases](https://github.com/TheAlgorithms/Go/blob/master/sorts/sorts_testcases.go) - -## Strings - * Levenshtein Distance - * [Levenshtein Distance](https://github.com/TheAlgorithms/Go/blob/master/strings/levenshtein_distance/levenshtein_distance.go) - * [Levenshtein Distance Test](https://github.com/TheAlgorithms/Go/blob/master/strings/levenshtein_distance/levenshtein_distance_test.go) - * Multiple String Matching - * Advanced Aho Corasick - * [Advanced Aho Corasick](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/advanced_aho_corasick/advanced_aho_corasick.go) - * [Advanced Aho Corasick Test](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/advanced_aho_corasick/advanced_aho_corasick_test.go) - * Aho Corasick - * [Aho Corasick](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/aho_corasick/aho_corasick.go) - * [Aho Corasick Test](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/aho_corasick/aho_corasick_test.go) - * Sbom - * [Sbom](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/sbom/sbom.go) - * [Sbom Test](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/sbom/sbom_test.go) - * Naive String Search - * [Naive String Search](https://github.com/TheAlgorithms/Go/blob/master/strings/naive_string_search/naive_string_search.go) - * [Naive String Search Test](https://github.com/TheAlgorithms/Go/blob/master/strings/naive_string_search/naive_string_search_test.go) - * Single String Matching - * Bom - * [Bom](https://github.com/TheAlgorithms/Go/blob/master/strings/single_string_matching/bom/bom.go) - * Horspool - * [Horspool](https://github.com/TheAlgorithms/Go/blob/master/strings/single_string_matching/horspool/horspool.go) - * Kmp - * [Kmp](https://github.com/TheAlgorithms/Go/blob/master/strings/single_string_matching/kmp/kmp.go) - * [Kmp Test](https://github.com/TheAlgorithms/Go/blob/master/strings/single_string_matching/kmp/kmp_test.go) diff --git a/README.md b/README.md index ff2f00c0e..903b6bf04 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,101 @@ Read our [Contribution Guidelines](CONTRIBUTING.md) before you contribute. ## List of Algorithms -See our [directory](DIRECTORY.md). + +## Ciphers +* [Caesar](https://github.com/TheAlgorithms/Go/blob/master/ciphers/caesar/) +* [Diffie Hellman Key Exchange](https://github.com/TheAlgorithms/Go/blob/master/ciphers/diffie_hellman_key_exchange/) +* [Polybius](https://github.com/TheAlgorithms/Go/blob/master/ciphers/polybius/) +* [Rot13](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rot13/) +* [Rsa Cipher](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rsa_cipher/) +* [Rsa Cipher Big](https://github.com/TheAlgorithms/Go/blob/master/ciphers/rsa_cipher_big/) +* [Xor Cipher](https://github.com/TheAlgorithms/Go/blob/master/ciphers/xor_cipher/) + +## Conversions +* [Roman To Integer](https://github.com/TheAlgorithms/Go/blob/master/conversions/roman_to_integer/) + +## Data Structures +* [Binary Tree](https://github.com/TheAlgorithms/Go/blob/master/data_structures/binary_tree/) +* [Dynamic Array](https://github.com/TheAlgorithms/Go/blob/master/data_structures/dynamic_array/) +* [Hashmap](https://github.com/TheAlgorithms/Go/blob/master/data_structures/hashmap/) +* Linked-List + * [Doubly Linked-list](https://github.com/TheAlgorithms/Go/blob/master/data_structures/linkedlist/doubly_linkedlist/) + * [Singly Linked-list](https://github.com/TheAlgorithms/Go/blob/master/data_structures/linkedlist/singly_linkedlist/) +* [Trie](https://github.com/TheAlgorithms/Go/blob/master/data_structures/trie/) + +## Design Patterns +* [Abstract Factory](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/abstract_factory/) +* [Builder](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/builder/) +* [Factory Method](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/factory_method/) +* [Prototype](https://github.com/TheAlgorithms/Go/blob/master/design_patterns/prototype/) + + +## Dynamic Programming +* [Binomial Coefficient](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/binomialcoefficient.go) +* [Fibonacci](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/fibonacci.go) | [Test](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/fibonacci_test.go) +* [Knapsack](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/knapsack.go) +* [Longest Common Subsequence](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/longestcommonsubsequence.go) +* [Longest Palindromic Subsequence](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/longestpalindromicsubsequence.go) +* [Matrix Multiplication](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/matrixmultiplication.go) +* [Cutting a Rod](https://github.com/TheAlgorithms/Go/blob/master/dynamic_programming/rodcutting.go) + +## Genetic Algorithm +* [Genetic Algorithm](https://github.com/TheAlgorithms/Go/blob/master/genetic_algorithm/geneticalgorithm.go) + +## Graphs +* [Breadth First Search](https://github.com/TheAlgorithms/Go/blob/master/graphs/breadth_first_search/) +* [Depth First Search](https://github.com/TheAlgorithms/Go/blob/master/graphs/depth_first_search/) +* [Floyd Warshall](https://github.com/TheAlgorithms/Go/blob/master/graphs/floyd_warshall/) + +## Math +* [Gcd](https://github.com/TheAlgorithms/Go/blob/master/math/gcd/) +* [Lcm](https://github.com/TheAlgorithms/Go/blob/master/math/lcm/) +* [Modular Arithmetic](https://github.com/TheAlgorithms/Go/blob/master/math/modular_arithmetic/) +* [Permutation](https://github.com/TheAlgorithms/Go/blob/master/math/permutation/) +* [Power](https://github.com/TheAlgorithms/Go/blob/master/math/power/) +* [Prime](https://github.com/TheAlgorithms/Go/blob/master/math/prime/) +* [Pythagoras](https://github.com/TheAlgorithms/Go/blob/master/math/pythagoras/) +* [Sieve](https://github.com/TheAlgorithms/Go/blob/master/math/sieve/) + + +## Other +* [Max Subarray Sum](https://github.com/TheAlgorithms/Go/blob/master/other/max_subarray_sum/) +* [Monte Carlo Pi](https://github.com/TheAlgorithms/Go/blob/master/other/monte_carlo_pi/) +* [Nested Brackets](https://github.com/TheAlgorithms/Go/blob/master/other/nested_brackets/) +* [Password Generator](https://github.com/TheAlgorithms/Go/blob/master/other/password_generator/) +* [String Combinations](https://github.com/TheAlgorithms/Go/blob/master/other/string_combinations/) + +## Searches +* [Binary Search](https://github.com/TheAlgorithms/Go/blob/master/searches/binary_search/) +* [Linear Search](https://github.com/TheAlgorithms/Go/blob/master/searches/linear_search/) + +## Set +* [Set](https://github.com/TheAlgorithms/Go/blob/master/set/set.go) + +## Sorts +* [Bubble Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/bubblesort.go) +* [Heap Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/heapsort.go) +* [Insertion Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/insertionsort.go) +* [Merge Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/mergesort.go) +* [Quick Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/quicksort.go) +* [Radix Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/radixsort.go) +* [Selection Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/selectionsort.go) +* [Shell Sort](https://github.com/TheAlgorithms/Go/blob/master/sorts/shellsort.go) + + +* Sorts Test + * [Sorts Test](https://github.com/TheAlgorithms/Go/blob/master/sorts/sorts_test.go) + * [Sorts Testcases](https://github.com/TheAlgorithms/Go/blob/master/sorts/sorts_testcases.go) + +## Strings +* [Levenshtein Distance](https://github.com/TheAlgorithms/Go/blob/master/strings/levenshtein_distance/) +* Multiple String Matching + * [Advanced Aho Corasick](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/advanced_aho_corasick/) + * [Aho Corasick](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/aho_corasick/) + * [Sbom](https://github.com/TheAlgorithms/Go/blob/master/strings/multiple_string_matching/sbom/) +* [Naive String Search](https://github.com/TheAlgorithms/Go/blob/master/strings/naive_string_search/) +* Single String Matching + * [Bom](https://github.com/TheAlgorithms/Go/blob/master/strings/single_string_matching/bom/) + * [Horspool](https://github.com/TheAlgorithms/Go/blob/master/strings/single_string_matching/horspool/) + * [Kmp](https://github.com/TheAlgorithms/Go/blob/master/strings/single_string_matching/kmp/) + diff --git a/ciphers/caesar/caesar_cipher.go b/ciphers/caesar/caesar.go similarity index 100% rename from ciphers/caesar/caesar_cipher.go rename to ciphers/caesar/caesar.go diff --git a/ciphers/diffie_hellman_key_exchange/diffie_hellman_key_exchange.go b/ciphers/diffie_hellman_key_exchange/diffiehellmankeyexchange.go similarity index 100% rename from ciphers/diffie_hellman_key_exchange/diffie_hellman_key_exchange.go rename to ciphers/diffie_hellman_key_exchange/diffiehellmankeyexchange.go diff --git a/ciphers/diffie_hellman_key_exchange/diffie_hellman_key_exchange_test.go b/ciphers/diffie_hellman_key_exchange/diffiehellmankeyexchange_test.go similarity index 100% rename from ciphers/diffie_hellman_key_exchange/diffie_hellman_key_exchange_test.go rename to ciphers/diffie_hellman_key_exchange/diffiehellmankeyexchange_test.go diff --git a/ciphers/rsa_cipher/rsa_cipher.go b/ciphers/rsa_cipher/rsacipher.go similarity index 100% rename from ciphers/rsa_cipher/rsa_cipher.go rename to ciphers/rsa_cipher/rsacipher.go diff --git a/ciphers/rsa_cipher/rsa_cipher_test.go b/ciphers/rsa_cipher/rsacipher_test.go similarity index 96% rename from ciphers/rsa_cipher/rsa_cipher_test.go rename to ciphers/rsa_cipher/rsacipher_test.go index c70040b40..e063276e8 100644 --- a/ciphers/rsa_cipher/rsa_cipher_test.go +++ b/ciphers/rsa_cipher/rsacipher_test.go @@ -24,7 +24,7 @@ var rsaTestData = []struct { "the quick brown fox jumps over the lazy dog.", }, { - "Encrypt full sentence from rsa_cipher.go main function", + "Encrypt full sentence from rsacipher.go main function", "I think RSA is really great", }, } diff --git a/ciphers/rsa_cipher_big/rsa_cipher_big.go b/ciphers/rsa_cipher_big/rsacipherbig.go similarity index 100% rename from ciphers/rsa_cipher_big/rsa_cipher_big.go rename to ciphers/rsa_cipher_big/rsacipherbig.go diff --git a/ciphers/rsa_cipher_big/rsa_cipher_big_test.go b/ciphers/rsa_cipher_big/rsacipherbig_test.go similarity index 95% rename from ciphers/rsa_cipher_big/rsa_cipher_big_test.go rename to ciphers/rsa_cipher_big/rsacipherbig_test.go index 973be9672..1efcd919d 100644 --- a/ciphers/rsa_cipher_big/rsa_cipher_big_test.go +++ b/ciphers/rsa_cipher_big/rsacipherbig_test.go @@ -23,7 +23,7 @@ var rsaTestData = []struct { "the quick brown fox jumps over the lazy dog.", }, { - "Encrypt full sentence from rsa_cipher_big.go main function", + "Encrypt full sentence from rsacipherbig.go main function", "Black Lives Matter, all lives can't matter until Black lives matter", }, } diff --git a/ciphers/xor_cipher/xor_cipher.go b/ciphers/xor_cipher/xorcipher.go similarity index 100% rename from ciphers/xor_cipher/xor_cipher.go rename to ciphers/xor_cipher/xorcipher.go diff --git a/ciphers/xor_cipher/xor_cipher_test.go b/ciphers/xor_cipher/xorcipher_test.go similarity index 100% rename from ciphers/xor_cipher/xor_cipher_test.go rename to ciphers/xor_cipher/xorcipher_test.go diff --git a/conversions/roman_to_integer/roman_to_integer.go b/conversions/roman_to_integer/romantointeger.go similarity index 100% rename from conversions/roman_to_integer/roman_to_integer.go rename to conversions/roman_to_integer/romantointeger.go diff --git a/conversions/roman_to_integer/roman_to_integer_test.go b/conversions/roman_to_integer/romantointeger_test.go similarity index 100% rename from conversions/roman_to_integer/roman_to_integer_test.go rename to conversions/roman_to_integer/romantointeger_test.go diff --git a/data_structures/binary_tree/binary_search_tree.go b/data_structures/binary_tree/binarysearchtree.go similarity index 100% rename from data_structures/binary_tree/binary_search_tree.go rename to data_structures/binary_tree/binarysearchtree.go diff --git a/data_structures/binary_tree/binary_tree.go b/data_structures/binary_tree/binarytree.go similarity index 79% rename from data_structures/binary_tree/binary_tree.go rename to data_structures/binary_tree/binarytree.go index 6ee12ec9c..4d4529994 100644 --- a/data_structures/binary_tree/binary_tree.go +++ b/data_structures/binary_tree/binarytree.go @@ -1,13 +1,6 @@ // Package binarytree basic binary tree and related operations package binarytree -// Max Function that returns max of two numbers - possibly already declared. -func Max(a, b int) int { - if a > b { - return a - } - return b -} /* func main() { diff --git a/data_structures/binary_tree/btree.go b/data_structures/binary_tree/btree.go index 0e0ad8224..3ccd3b484 100644 --- a/data_structures/binary_tree/btree.go +++ b/data_structures/binary_tree/btree.go @@ -115,3 +115,12 @@ func LevelOrder(root *Node) { } } } + + +// Max Function that returns max of two numbers - possibly already declared. +func Max(a, b int) int { + if a > b { + return a + } + return b +} \ No newline at end of file diff --git a/data_structures/dynamic_array/dynamic_array.go b/data_structures/dynamic_array/dynamicarray.go similarity index 98% rename from data_structures/dynamic_array/dynamic_array.go rename to data_structures/dynamic_array/dynamicarray.go index 6e259c4b5..1d9a9763b 100644 --- a/data_structures/dynamic_array/dynamic_array.go +++ b/data_structures/dynamic_array/dynamicarray.go @@ -6,7 +6,7 @@ // https://blog.golang.org/slices-intro // https://blog.golang.org/slices // authors [Wesllhey Holanda](https://github.com/wesllhey), [Milad](https://github.com/miraddo) -// see dynamic_array.go, dynamic_array_test.go +// see dynamicarray.go, dynamicarray_test.go package dynamicarray diff --git a/data_structures/dynamic_array/dynamic_array_test.go b/data_structures/dynamic_array/dynamicarray_test.go similarity index 100% rename from data_structures/dynamic_array/dynamic_array_test.go rename to data_structures/dynamic_array/dynamicarray_test.go diff --git a/data_structures/linkedlist/doubly_linkedlist/doubly_linkedlist.go b/data_structures/linkedlist/doubly_linkedlist/doublylinkedlist.go similarity index 100% rename from data_structures/linkedlist/doubly_linkedlist/doubly_linkedlist.go rename to data_structures/linkedlist/doubly_linkedlist/doublylinkedlist.go diff --git a/data_structures/linkedlist/doubly_linkedlist/doubly_linkedlist_test.go b/data_structures/linkedlist/doubly_linkedlist/doublylinkedlist_test.go similarity index 100% rename from data_structures/linkedlist/doubly_linkedlist/doubly_linkedlist_test.go rename to data_structures/linkedlist/doubly_linkedlist/doublylinkedlist_test.go diff --git a/data_structures/linkedlist/singly_linkedlist/singly_linkedlist.go b/data_structures/linkedlist/singly_linkedlist/singlylinkedlist.go similarity index 100% rename from data_structures/linkedlist/singly_linkedlist/singly_linkedlist.go rename to data_structures/linkedlist/singly_linkedlist/singlylinkedlist.go diff --git a/data_structures/linkedlist/singly_linkedlist/singly_linkedlist_test.go b/data_structures/linkedlist/singly_linkedlist/singlylinkedlist_test.go similarity index 100% rename from data_structures/linkedlist/singly_linkedlist/singly_linkedlist_test.go rename to data_structures/linkedlist/singly_linkedlist/singlylinkedlist_test.go diff --git a/design_patterns/abstract_factory/abstract_factory_test.go b/design_patterns/abstract_factory/abstractfactory_test.go similarity index 100% rename from design_patterns/abstract_factory/abstract_factory_test.go rename to design_patterns/abstract_factory/abstractfactory_test.go diff --git a/design_patterns/abstract_factory/adidas_shoe.go b/design_patterns/abstract_factory/adidasshoe.go similarity index 100% rename from design_patterns/abstract_factory/adidas_shoe.go rename to design_patterns/abstract_factory/adidasshoe.go diff --git a/design_patterns/abstract_factory/i_shirt.go b/design_patterns/abstract_factory/ishirt.go similarity index 100% rename from design_patterns/abstract_factory/i_shirt.go rename to design_patterns/abstract_factory/ishirt.go diff --git a/design_patterns/abstract_factory/i_shoe.go b/design_patterns/abstract_factory/ishoe.go similarity index 100% rename from design_patterns/abstract_factory/i_shoe.go rename to design_patterns/abstract_factory/ishoe.go diff --git a/design_patterns/abstract_factory/i_sports_factory.go b/design_patterns/abstract_factory/isportsfactory.go similarity index 100% rename from design_patterns/abstract_factory/i_sports_factory.go rename to design_patterns/abstract_factory/isportsfactory.go diff --git a/design_patterns/abstract_factory/nike_shirt.go b/design_patterns/abstract_factory/nikeshirt.go similarity index 100% rename from design_patterns/abstract_factory/nike_shirt.go rename to design_patterns/abstract_factory/nikeshirt.go diff --git a/design_patterns/abstract_factory/nike_shoe.go b/design_patterns/abstract_factory/nikeshoe.go similarity index 100% rename from design_patterns/abstract_factory/nike_shoe.go rename to design_patterns/abstract_factory/nikeshoe.go diff --git a/design_patterns/builder/builder_interface.go b/design_patterns/builder/builderinterface.go similarity index 100% rename from design_patterns/builder/builder_interface.go rename to design_patterns/builder/builderinterface.go diff --git a/design_patterns/builder/builder_pattern_test.go b/design_patterns/builder/builderpattern_test.go similarity index 100% rename from design_patterns/builder/builder_pattern_test.go rename to design_patterns/builder/builderpattern_test.go diff --git a/design_patterns/builder/igloo_builder.go b/design_patterns/builder/igloobuilder.go similarity index 100% rename from design_patterns/builder/igloo_builder.go rename to design_patterns/builder/igloobuilder.go diff --git a/design_patterns/builder/normal_builder.go b/design_patterns/builder/normalbuilder.go similarity index 100% rename from design_patterns/builder/normal_builder.go rename to design_patterns/builder/normalbuilder.go diff --git a/design_patterns/factory_method/accounting_department.go b/design_patterns/factory_method/accountingdepartment.go similarity index 100% rename from design_patterns/factory_method/accounting_department.go rename to design_patterns/factory_method/accountingdepartment.go diff --git a/design_patterns/factory_method/department_factory.go b/design_patterns/factory_method/departmentfactory.go similarity index 100% rename from design_patterns/factory_method/department_factory.go rename to design_patterns/factory_method/departmentfactory.go diff --git a/design_patterns/factory_method/factory_method_test.go b/design_patterns/factory_method/factorymethod_test.go similarity index 100% rename from design_patterns/factory_method/factory_method_test.go rename to design_patterns/factory_method/factorymethod_test.go diff --git a/design_patterns/factory_method/finance_department.go b/design_patterns/factory_method/financedepartment.go similarity index 100% rename from design_patterns/factory_method/finance_department.go rename to design_patterns/factory_method/financedepartment.go diff --git a/design_patterns/factory_method/i_department.go b/design_patterns/factory_method/idepartment.go similarity index 100% rename from design_patterns/factory_method/i_department.go rename to design_patterns/factory_method/idepartment.go diff --git a/design_patterns/prototype/node_interface.go b/design_patterns/prototype/nodeinterface.go similarity index 100% rename from design_patterns/prototype/node_interface.go rename to design_patterns/prototype/nodeinterface.go diff --git a/dynamic_programming/binomial_coefficient.go b/dynamic_programming/binomialcoefficient.go similarity index 100% rename from dynamic_programming/binomial_coefficient.go rename to dynamic_programming/binomialcoefficient.go diff --git a/dynamic_programming/longest_common_subsequence.go b/dynamic_programming/longestcommonsubsequence.go similarity index 100% rename from dynamic_programming/longest_common_subsequence.go rename to dynamic_programming/longestcommonsubsequence.go diff --git a/dynamic_programming/longest_palindromic_subsequence.go b/dynamic_programming/longestpalindromicsubsequence.go similarity index 100% rename from dynamic_programming/longest_palindromic_subsequence.go rename to dynamic_programming/longestpalindromicsubsequence.go diff --git a/dynamic_programming/matrix_multiplication.go b/dynamic_programming/matrixmultiplication.go similarity index 100% rename from dynamic_programming/matrix_multiplication.go rename to dynamic_programming/matrixmultiplication.go diff --git a/dynamic_programming/rod_cutting.go b/dynamic_programming/rodcutting.go similarity index 100% rename from dynamic_programming/rod_cutting.go rename to dynamic_programming/rodcutting.go diff --git a/genetic_algorithm/genetic_algo.go b/genetic_algorithm/geneticalgorithm.go similarity index 100% rename from genetic_algorithm/genetic_algo.go rename to genetic_algorithm/geneticalgorithm.go diff --git a/graphs/search/breadth_first_search.go b/graphs/breadth_first_search/breadthfirstsearch.go similarity index 97% rename from graphs/search/breadth_first_search.go rename to graphs/breadth_first_search/breadthfirstsearch.go index 6781be597..c80bf8209 100644 --- a/graphs/search/breadth_first_search.go +++ b/graphs/breadth_first_search/breadthfirstsearch.go @@ -1,6 +1,6 @@ // Package search Graph search algorithms // reference: https://en.wikipedia.org/wiki/Tree_traversal -package search +package breadth_first_search /*BreadthFirstSearch is an algorithm for traversing and searching graph data structures. It starts at an arbitrary node of a graph, and explores all of the neighbor nodes diff --git a/graphs/search/breadth_first_search_test.go b/graphs/breadth_first_search/breadthfirstsearch_test.go similarity index 98% rename from graphs/search/breadth_first_search_test.go rename to graphs/breadth_first_search/breadthfirstsearch_test.go index d476c3bc1..d80d767f5 100644 --- a/graphs/search/breadth_first_search_test.go +++ b/graphs/breadth_first_search/breadthfirstsearch_test.go @@ -1,4 +1,4 @@ -package search +package breadth_first_search import ( "testing" diff --git a/graphs/depth_first_search/depth_first_search.go b/graphs/depth_first_search/depthfirstsearch.go similarity index 100% rename from graphs/depth_first_search/depth_first_search.go rename to graphs/depth_first_search/depthfirstsearch.go diff --git a/graphs/floyd_warshall/floyd_warshall.go b/graphs/floyd_warshall/floydwarshall.go similarity index 100% rename from graphs/floyd_warshall/floyd_warshall.go rename to graphs/floyd_warshall/floydwarshall.go diff --git a/math/gcd/gcd_iterative.go b/math/gcd/gcditerative.go similarity index 100% rename from math/gcd/gcd_iterative.go rename to math/gcd/gcditerative.go diff --git a/math/modular_arithmetic/modular_exponentiation.go b/math/modular_arithmetic/modularexponentiation.go similarity index 100% rename from math/modular_arithmetic/modular_exponentiation.go rename to math/modular_arithmetic/modularexponentiation.go diff --git a/math/modular_arithmetic/modular_exponentiation_test.go b/math/modular_arithmetic/modularexponentiation_test.go similarity index 100% rename from math/modular_arithmetic/modular_exponentiation_test.go rename to math/modular_arithmetic/modularexponentiation_test.go diff --git a/math/power/fast_exponent.go b/math/power/fastexponent.go similarity index 100% rename from math/power/fast_exponent.go rename to math/power/fastexponent.go diff --git a/math/power/fast_exponent_test.go b/math/power/fastexponent_test.go similarity index 100% rename from math/power/fast_exponent_test.go rename to math/power/fastexponent_test.go diff --git a/math/prime/miller_rabin_primality_test.go b/math/prime/millerrabinprimalitytest.go similarity index 100% rename from math/prime/miller_rabin_primality_test.go rename to math/prime/millerrabinprimalitytest.go diff --git a/math/prime/prime_check.go b/math/prime/primecheck.go similarity index 100% rename from math/prime/prime_check.go rename to math/prime/primecheck.go diff --git a/math/prime/prime_test.go b/math/prime/primecheck_test.go similarity index 100% rename from math/prime/prime_test.go rename to math/prime/primecheck_test.go diff --git a/other/max_subarray_sum/max_subarray_sum.go b/other/max_subarray_sum/maxsubarraysum.go similarity index 100% rename from other/max_subarray_sum/max_subarray_sum.go rename to other/max_subarray_sum/maxsubarraysum.go diff --git a/other/monte_carlo_pi/monte_carlo_pi.go b/other/monte_carlo_pi/montecarlopi.go similarity index 100% rename from other/monte_carlo_pi/monte_carlo_pi.go rename to other/monte_carlo_pi/montecarlopi.go diff --git a/other/monte_carlo_pi/monte_carlo_pi_test.go b/other/monte_carlo_pi/montecarlopi_test.go similarity index 100% rename from other/monte_carlo_pi/monte_carlo_pi_test.go rename to other/monte_carlo_pi/montecarlopi_test.go diff --git a/other/nested_brackets/nested_brackets.go b/other/nested_brackets/nestedbrackets.go similarity index 100% rename from other/nested_brackets/nested_brackets.go rename to other/nested_brackets/nestedbrackets.go diff --git a/other/password_generator/password_generator.go b/other/password_generator/passwordgenerator.go similarity index 100% rename from other/password_generator/password_generator.go rename to other/password_generator/passwordgenerator.go diff --git a/other/string_combinations/string_combinations.go b/other/string_combinations/stringcombinations.go similarity index 100% rename from other/string_combinations/string_combinations.go rename to other/string_combinations/stringcombinations.go diff --git a/searches/binary_search.go b/searches/binary_search/binarysearch.go similarity index 97% rename from searches/binary_search.go rename to searches/binary_search/binarysearch.go index 725c10c07..f3c9b7840 100644 --- a/searches/binary_search.go +++ b/searches/binary_search/binarysearch.go @@ -1,4 +1,4 @@ -package searches +package binarysearch // BinarySearch Binary Search func BinarySearch(array []int, target int, lowIndex int, highIndex int) int { diff --git a/searches/search_test.go b/searches/binary_search/binarysearch_test.go similarity index 79% rename from searches/search_test.go rename to searches/binary_search/binarysearch_test.go index dccd93c11..82909e99c 100644 --- a/searches/search_test.go +++ b/searches/binary_search/binarysearch_test.go @@ -1,6 +1,8 @@ -package searches +package binarysearch -import "testing" +import ( + "testing" +) type searchTest struct { data []int @@ -38,12 +40,3 @@ func TestIterBinarySearch(t *testing.T) { } } } - -func TestLinearSearch(t *testing.T) { - for _, test := range searchTests { - actual := LinearSearch(test.data, test.key) - if actual != test.expected { - t.Errorf("test %s failed", test.name) - } - } -} diff --git a/searches/linear_search.go b/searches/linear_search/linearsearch.go similarity index 91% rename from searches/linear_search.go rename to searches/linear_search/linearsearch.go index a41ef8a80..89be4fd8b 100644 --- a/searches/linear_search.go +++ b/searches/linear_search/linearsearch.go @@ -1,4 +1,4 @@ -package searches +package linear_search // LinearSearch Simple linear search algorithm that iterates over all elements of an array in the worst case scenario func LinearSearch(array []int, query int) int { diff --git a/searches/linear_search/linearsearch_test.go b/searches/linear_search/linearsearch_test.go new file mode 100644 index 000000000..d5db0c416 --- /dev/null +++ b/searches/linear_search/linearsearch_test.go @@ -0,0 +1,34 @@ +package linear_search + +import ( + "testing" +) + +type searchTest struct { + data []int + key int + expected int + name string +} + +var searchTests = []searchTest{ + //Sanity + {[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 1, 0, "Sanity"}, + {[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 5, 4, "Sanity"}, + {[]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, 10, 9, "Sanity"}, + //Absent + {[]int{1, 4, 5, 6, 7, 10}, -25, -1, "Absent"}, + {[]int{1, 4, 5, 6, 7, 10}, 25, -1, "Absent"}, + //Empty slice + {[]int{}, 2, -1, "Empty"}, +} + + +func TestLinearSearch(t *testing.T) { + for _, test := range searchTests { + actual := LinearSearch(test.data, test.key) + if actual != test.expected { + t.Errorf("test %s failed", test.name) + } + } +} diff --git a/sorts/bubble_sort.go b/sorts/bubblesort.go similarity index 100% rename from sorts/bubble_sort.go rename to sorts/bubblesort.go diff --git a/sorts/heap_sort.go b/sorts/heapsort.go similarity index 100% rename from sorts/heap_sort.go rename to sorts/heapsort.go diff --git a/sorts/insertion_sort.go b/sorts/insertionsort.go similarity index 100% rename from sorts/insertion_sort.go rename to sorts/insertionsort.go diff --git a/sorts/merge_sort.go b/sorts/mergesort.go similarity index 100% rename from sorts/merge_sort.go rename to sorts/mergesort.go diff --git a/sorts/quick_sort.go b/sorts/quicksort.go similarity index 100% rename from sorts/quick_sort.go rename to sorts/quicksort.go diff --git a/sorts/radix_sort.go b/sorts/radixsort.go similarity index 100% rename from sorts/radix_sort.go rename to sorts/radixsort.go diff --git a/sorts/selection_sort.go b/sorts/selectionsort.go similarity index 100% rename from sorts/selection_sort.go rename to sorts/selectionsort.go diff --git a/sorts/shell_sort.go b/sorts/shellsort.go similarity index 100% rename from sorts/shell_sort.go rename to sorts/shellsort.go diff --git a/strings/levenshtein_distance/levenshtein_distance.go b/strings/levenshtein_distance/levenshteindistance.go similarity index 100% rename from strings/levenshtein_distance/levenshtein_distance.go rename to strings/levenshtein_distance/levenshteindistance.go diff --git a/strings/levenshtein_distance/levenshtein_distance_test.go b/strings/levenshtein_distance/levenshteindistance_test.go similarity index 100% rename from strings/levenshtein_distance/levenshtein_distance_test.go rename to strings/levenshtein_distance/levenshteindistance_test.go diff --git a/strings/multiple_string_matching/advanced_aho_corasick/advanced_aho_corasick.go b/strings/multiple_string_matching/advanced_aho_corasick/advancedahocorasick.go similarity index 100% rename from strings/multiple_string_matching/advanced_aho_corasick/advanced_aho_corasick.go rename to strings/multiple_string_matching/advanced_aho_corasick/advancedahocorasick.go diff --git a/strings/multiple_string_matching/advanced_aho_corasick/advanced_aho_corasick_test.go b/strings/multiple_string_matching/advanced_aho_corasick/advancedahocorasick_test.go similarity index 100% rename from strings/multiple_string_matching/advanced_aho_corasick/advanced_aho_corasick_test.go rename to strings/multiple_string_matching/advanced_aho_corasick/advancedahocorasick_test.go diff --git a/strings/multiple_string_matching/aho_corasick/aho_corasick.go b/strings/multiple_string_matching/aho_corasick/ahocorasick.go similarity index 100% rename from strings/multiple_string_matching/aho_corasick/aho_corasick.go rename to strings/multiple_string_matching/aho_corasick/ahocorasick.go diff --git a/strings/multiple_string_matching/aho_corasick/aho_corasick_test.go b/strings/multiple_string_matching/aho_corasick/ahocorasick_test.go similarity index 100% rename from strings/multiple_string_matching/aho_corasick/aho_corasick_test.go rename to strings/multiple_string_matching/aho_corasick/ahocorasick_test.go diff --git a/strings/naive_string_search/naive_string_search.go b/strings/naive_string_search/naivestringsearch.go similarity index 100% rename from strings/naive_string_search/naive_string_search.go rename to strings/naive_string_search/naivestringsearch.go diff --git a/strings/naive_string_search/naive_string_search_test.go b/strings/naive_string_search/naivestringsearch_test.go similarity index 100% rename from strings/naive_string_search/naive_string_search_test.go rename to strings/naive_string_search/naivestringsearch_test.go