{"id":22880691,"url":"https://github.com/fajarnugraha37/go_external_sort","last_synced_at":"2026-02-03T17:30:52.827Z","repository":{"id":267496900,"uuid":"901431451","full_name":"fajarnugraha37/go_external_sort","owner":"fajarnugraha37","description":"This project demonstrates an external sorting algorithm in Go, designed to efficiently handle large data sets that exceed available memory. The program reads a random string data set from a file, sorts it using an external merge sort technique, and writes the sorted output to a new file.","archived":false,"fork":false,"pushed_at":"2024-12-11T06:06:52.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T00:49:03.356Z","etag":null,"topics":["algorithm","algorithms-and-data-structures","external-sorting","go","golang","sorting","sorting-algorithms"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fajarnugraha37.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2024-12-10T16:39:59.000Z","updated_at":"2024-12-11T06:06:56.000Z","dependencies_parsed_at":"2024-12-10T18:20:52.532Z","dependency_job_id":"595e06c3-b42c-4b3c-847c-4fc409200767","html_url":"https://github.com/fajarnugraha37/go_external_sort","commit_stats":null,"previous_names":["fajarnugraha37/go_external_sort"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fajarnugraha37/go_external_sort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fajarnugraha37%2Fgo_external_sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fajarnugraha37%2Fgo_external_sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fajarnugraha37%2Fgo_external_sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fajarnugraha37%2Fgo_external_sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fajarnugraha37","download_url":"https://codeload.github.com/fajarnugraha37/go_external_sort/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fajarnugraha37%2Fgo_external_sort/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29050780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T15:43:47.601Z","status":"ssl_error","status_checked_at":"2026-02-03T15:43:46.709Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["algorithm","algorithms-and-data-structures","external-sorting","go","golang","sorting","sorting-algorithms"],"created_at":"2024-12-13T17:26:58.910Z","updated_at":"2026-02-03T17:30:52.810Z","avatar_url":"https://github.com/fajarnugraha37.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# External Sorting in Go\n\nThis project implements an external sorting algorithm in Go, capable of handling large datasets that exceed available memory. The program reads a dataset of random strings from a file, sorts them, and writes the sorted output to a new file. It includes a dataset generator that creates random strings for testing purposes.\n\n## Table of Contents\n\n- [External Sorting in Go](#external-sorting-in-go)\n- [Features](#features)\n- [Project Structure](#project-structure)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Build](#build)\n  - [Simple Build](#simple-build)\n  - [Optimized Build](#optimized-build)\n  - [Cross-Compilation](#cross-compilation)\n- [Usage](#usage)\n  - [Generating a Dataset](#generating-a-dataset)\n  - [Sorting the Dataset](#sorting-the-dataset)\n- [How It Works](#how-it-works)\n- [Sequence Diagram](#sequence-diagram)\n- [Memory Management](#memory-management)\n- [Contributing](#contributing)\n- [License](#license)\n  \n## Features\n\n- Generates a dataset of random strings.\n- Implements external merge sort to handle large datasets.\n- Uses a temporary directory for storing intermediate sorted chunks.\n- Supports sorting of strings.\n\n## Project Structure\n    go_external_sort/\n    │\n    ├── cmd/main.go                \n    │   ├── dataset/\n    │        └── main.go        # Entry point of the program to generate dataset\n    │   └── sort\n    │        └── main.go        # Entry point of the program to sort dataset\n    ├── sorter/\n    │   ├── sorter.go          # External sorting logic\n    │   └── merge.go           # Merging sorted chunks\n    └── utils/\n        ├── file.go            # File handling utilities\n        └── logger.go          # Logging utilities\n\n## Requirements\n\n- Go 1.22.3 or later\n\n## Installation\n\n1. Clone the repository:\n```bash\ngit clone https://github.com/fajarnugraha37/go_external_sort.git \ncd go_external_sort\n```\n\n2. Ensure you have Go installed on your machine. You can download it from [golang.org](https://go.dev/dl/).\n\n## Build\n\n### Simple Build\n\nTo build the project for development, you can use the following command:\n```bash\ngo build -o ./bin/dataset.exe ./cmd/dataset/main.go\ngo build -o ./bin/sort.exe ./cmd/sort/main.go\n```\nThis command compiles the code and creates executables in the bin directory.\n\n### Optimized Build\n\nFor a optimized-optimized build, you can use the following command:\n```bash\ngo build -o ./bin/dataset.exe -ldflags=\"-s -w\" ./cmd/dataset/main.go\ngo build -o ./bin/sort.exe -ldflags=\"-s -w\" ./cmd/sort/main.go\n```\n- `-ldflags=\"-s -w\"`: This flag reduces the size of the binary by omitting the symbol table and debug\n\n### Cross-Compilation\n\nIf you are on a different operating system and want to cross-compile for another OS, you can set the `GOOS` and `GOARCH` environment variables accordingly.\n\n## Usage\n\n### Generating a Dataset\n\nTo generate a dataset of random strings, use the following command:\n```bash\ngo run ./cmd/dataset/main.go -output dataset_input.txt -count 10000000 -length 16\n```\nor\n```bash\n./bin/dataset.exe -output dataset_input.txt -count 10000000 -length 16\n```\n- `-output`: Path to the output file where the dataset will be saved.\n- `-count`: Number of random strings to generate (default is 100,000).\n- `-length`: Length of each random string (default is 10).\n\n### Sorting the Dataset\n\nTo sort the generated dataset, use the following command:\n```bash\ngo run ./cmd/sort/main.go -input dataset_input.txt -output dataset_output.txt\n```\nor\n```bash\n./bin/sort.exe -input dataset_input.txt -output dataset_output.txt\n```\n- `-input`: Path to the input file containing the dataset to be sorted.\n- `-output`: Path to the output file where the sorted dataset will be saved.\n\n## How It Works\n\n1. **Dataset Generation**: The `./cmd/dataset/main.go` file generates a specified number of random strings and writes them to a file.\n2. **External Sorting**: The `./cmd/sort/main.go` file orchestrates the sorting process:\n   - It reads the dataset from the input file.\n   - It splits the dataset into manageable chunks, sorts each chunk, and writes them to temporary files.\n   - It merges the sorted chunks into a final sorted output file.\n  \n## Sequence Diagram\n\n```mermaid\nsequenceDiagram\n    participant User\n    participant Generator\n    participant Sorter\n    participant FileSystem as FS\n    participant TempDirectory as TempDir\n\n    User-\u003e\u003eGenerator: Run dataset generation command\n    Generator-\u003e\u003eFS: Create dataset file\n    FS--\u003e\u003eGenerator: Confirm file creation\n    Generator-\u003e\u003eFS: Write random strings to dataset file\n    FS--\u003e\u003eGenerator: Confirm write completion\n    Generator-\u003e\u003eUser: Dataset generated successfully\n\n    User-\u003e\u003eSorter: Run sorting command\n    Sorter-\u003e\u003eFS: Open dataset file\n    FS--\u003e\u003eSorter: Provide dataset file\n    Sorter-\u003e\u003eTempDir: Create temp directory (if not exists)\n    Sorter-\u003e\u003eFS: Read dataset file\n    FS--\u003e\u003eSorter: Provide dataset content\n    Sorter-\u003e\u003eSorter: Split dataset into chunks\n    Sorter-\u003e\u003eSorter: Sort each chunk\n    Sorter-\u003e\u003eTempDir: Write sorted chunks to temp files\n    TempDir--\u003e\u003eSorter: Confirm chunk write completion\n    Sorter-\u003e\u003eTempDir: Merge sorted chunks\n    Sorter-\u003e\u003eFS: Write sorted output file\n    FS--\u003e\u003eSorter: Confirm output file creation\n    Sorter-\u003e\u003eUser: Sorting completed successfully\n```\n- `Participants`: The diagram includes five participants: User, Generator, Sorter, FileSystem, and TempDirectory.\n- `Interactions`: The arrows represent the interactions between these participants, showing the flow of commands and responses during the dataset generation and sorting processes.\n\n## Memory Management\n\nThe program is designed to use minimal memory by:\n- Limiting the size of each chunk to 10 MB.\n- Using buffered I/O for efficient file operations.\n- Storing temporary files in a dedicated `temp` directory within the working directory.\n\n## Contributing\n\nContributions are welcome! If you have suggestions or improvements, feel free to open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffajarnugraha37%2Fgo_external_sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffajarnugraha37%2Fgo_external_sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffajarnugraha37%2Fgo_external_sort/lists"}