{"id":19782672,"url":"https://github.com/freddiehaddad/justification","last_synced_at":"2025-02-28T06:48:26.142Z","repository":{"id":225268071,"uuid":"765516710","full_name":"freddiehaddad/justification","owner":"freddiehaddad","description":"Multithreaded Text Justification","archived":false,"fork":false,"pushed_at":"2024-03-01T15:39:11.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-24T05:38:32.845Z","etag":null,"topics":["concurrency","concurrent-programming","go","golang","leetcode","leetcode-go","leetcode-golang","leetcode-solution","multithreading","parallel-programming"],"latest_commit_sha":null,"homepage":"https://leetcode.com/problems/text-justification/description/?envType=study-plan-v2\u0026envId=top-interview-150","language":"Go","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/freddiehaddad.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":"2024-03-01T04:20:49.000Z","updated_at":"2024-10-18T15:21:58.000Z","dependencies_parsed_at":"2024-03-01T05:29:11.876Z","dependency_job_id":"e8fba9dd-096a-4c82-afc5-3c5c9156b5aa","html_url":"https://github.com/freddiehaddad/justification","commit_stats":null,"previous_names":["freddiehaddad/justification"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freddiehaddad%2Fjustification","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freddiehaddad%2Fjustification/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freddiehaddad%2Fjustification/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/freddiehaddad%2Fjustification/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/freddiehaddad","download_url":"https://codeload.github.com/freddiehaddad/justification/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241113890,"owners_count":19911984,"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":["concurrency","concurrent-programming","go","golang","leetcode","leetcode-go","leetcode-golang","leetcode-solution","multithreading","parallel-programming"],"created_at":"2024-11-12T06:05:47.967Z","updated_at":"2025-02-28T06:48:26.115Z","avatar_url":"https://github.com/freddiehaddad.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multithreaded Text Justification\n\nProgram that reads an array of words and generates an array of strings made up\nof the words fully justified such that each array element's length is set to the\nspecified width.\n\nThe program works by reading words from the input array until the total width\nwith spaces would exceed the specified line width. A thread is then created that\nfully justifies the words and creates a string. The process repeats for all\nlines excluding the last line. The last line is left justified in in a separate\nthread as well.\n\nIn addition to the words provided as input to the justification threads, the\nline number is also provided.\n\nWhen the threads are finished justifying the line, the data is written to a\nchannel.\n\nAnother thread waiting for input from the channel writes the justified lines to\nan array preserving the order by the provided line number. The array is\npre-sized to the maximum number in order to handle asynchronous arrival of lines\nand to avoid the need for a synchronization primitive (i.e. mutex). This is an\nexample of a lock free algorithm.\n\n```text\n+------------------------------------------+\n| [\"foo\", \"bar\", \"baz\", \"foobar\", ...]   G |\n|                                          |\n|                                          |\n| FullJustifiy()                           |\n+---------------------+--------------------+\n                      |\n                      +------------------------------------+\n                                                           |\n                                                           v\n  +----------------------------------+       +--------------------------+\n  | [\"foo  bar\", \"baz     \", ...]  G |       | [\"foo\", \"bar\"]         G |-+\n  |                                  |       |                          | |-+\n  |                                  |\u003c------+                          | | |\n  | processIncomingLines()           |       | *JustifyLine()           | | |\n  +----------------------------------+       +--------------------------+ | |\n                                               +--------------------------+ |\n                                                 +--------------------------+\n\nG: Go Routine\n```\n\n## Examples\n\n```Go\nwords := []string{\n    \"Science\", \"is\", \"what\", \"we\", \"understand\", \"well\", \"enough\", \"to\",\n    \"explain\", \"to\", \"a\", \"computer.\", \"Art\", \"is\", \"everything\", \"else\",\n    \"we\", \"do\",\n}\nwidth := 20\nresult := []string{\n    \"Science  is  what we\",\n    \"understand      well\",\n    \"enough to explain to\",\n    \"a  computer.  Art is\",\n    \"everything  else  we\",\n    \"do                  \",\n},\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreddiehaddad%2Fjustification","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreddiehaddad%2Fjustification","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreddiehaddad%2Fjustification/lists"}