{"id":21978492,"url":"https://github.com/shivammg/ppds","last_synced_at":"2025-04-05T14:07:03.670Z","repository":{"id":57487578,"uuid":"134070544","full_name":"shivamMg/ppds","owner":"shivamMg","description":"Pretty Print Data Structures","archived":false,"fork":false,"pushed_at":"2023-07-22T13:37:44.000Z","size":43,"stargazers_count":345,"open_issues_count":1,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-29T13:08:25.757Z","etag":null,"topics":["data-structures","go"],"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/shivamMg.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}},"created_at":"2018-05-19T14:44:18.000Z","updated_at":"2025-02-23T15:14:46.000Z","dependencies_parsed_at":"2024-06-18T15:19:48.028Z","dependency_job_id":"d932f10d-705b-4805-a7a0-00967f21ae79","html_url":"https://github.com/shivamMg/ppds","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivamMg%2Fppds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivamMg%2Fppds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivamMg%2Fppds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shivamMg%2Fppds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shivamMg","download_url":"https://codeload.github.com/shivamMg/ppds/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345853,"owners_count":20924102,"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":["data-structures","go"],"created_at":"2024-11-29T16:24:31.518Z","updated_at":"2025-04-05T14:07:03.638Z","avatar_url":"https://github.com/shivamMg.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ppds [![godoc](https://godoc.org/github.com/shivammg/ppds?status.svg)](https://godoc.org/github.com/shivamMg/ppds) ![Build](https://github.com/shivamMg/trie/actions/workflows/ci.yml/badge.svg?branch=master) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nPretty Print Data Structures\n\nStacks, queues, trees and linked lists are data structures that you might find yourself working with quite often. This library lets you pretty print these with minimum effort. Certain assumptions can be made for each data structure, for instance, a stack or a queue will have methods synonymous to Push (insert) and Pop (remove), a tree node will have links to its child nodes, or a linked list node will have a link to its next adjacent node. This library utilises those assumptions, and exports interfaces and functions to pretty print them.\n\nThe following data structures are supported:\n\n### Trees\n[![tree](https://godoc.org/github.com/shivammg/ppds?status.svg)](https://godoc.org/github.com/shivamMg/ppds/tree)\n\nA type that satisfies the following interface can be printed using `tree.Print`.\n\n```\ntype Node interface {\n\tData() interface{}\n\tChildren() []Node\n}\n```\n\n```\nMusic\n├──────────────────────────────────────────┐\nClassical                                  Pop/Rock\n├────────────────────┐                     ├───────────────────────────┐\nInstrumental         Vocal                 Organic                     Electronic\n├──────┐             ├─────────────┐       ├────────────┐              ├────────────────┐\nPiano  Orchestra     Opera         Chorus  Rock         Country        Pop              Techno\n       ├──────┐      ├─────┐               │            ├────────┐     ├─────────┐      ├────────────┐\n       Light  Heavy  Male  Female          Heavy metal  Dancing  Soft  Late pop  Disco  Soft techno  Hard techno\n```\n\nIf branching factor is high or data lengths are large, it would make more sense to print the tree horizontally. That can be done using `tree.PrintHr` function.\n\n```\nMusic ┬─ Classical ┬─ Instrumental ┬─ Piano\n      │            │               └─ Orchestra ┬─ Light\n      │            │                            └─ Heavy\n      │            └─ Vocal ┬─ Opera ┬─ Male\n      │                     │        └─ Female\n      │                     └─ Chorus\n      └─ Pop/Rock ┬─ Organic ┬─ Rock ── Heavy metal\n                  │          └─ Country ┬─ Dancing\n                  │                     └─ Soft\n                  └─ Electronic ┬─ Pop ┬─ Late pop\n                                │      └─ Disco\n                                └─ Techno ┬─ Soft techno\n                                          └─ Hard techno\n```\n\nInspired by [tree](http://mama.indstate.edu/users/ice/tree/), a popular directory listing command, `tree.PrintHrn` prints the tree in similar style. Every node is printed on a separate line making the output tree look less cluttered and more elegant. It does take up vertical space though.\n\n```\nMusic\n├─ Classical\n│  ├─ Instrumental\n│  │  ├─ Piano\n│  │  └─ Orchestra\n│  │     ├─ Light\n│  │     └─ Heavy\n│  └─ Vocal\n│     ├─ Opera\n│     │  ├─ Male\n│     │  └─ Female\n│     └─ Chorus\n└─ Pop/Rock\n   ├─ Organic\n   │  ├─ Rock\n   │  │  └─ Heavy metal\n   │  └─ Country\n   │     ├─ Dancing\n   │     └─ Soft\n   └─ Electronic\n      ├─ Pop\n      │  ├─ Late pop\n      │  └─ Disco\n      └─ Techno\n         ├─ Soft techno\n         └─ Hard techno\n```\n\n### Linked Lists\n[![list](https://godoc.org/github.com/shivammg/ppds?status.svg)](https://godoc.org/github.com/shivamMg/ppds/list)\n\n```\ntype Node interface {\n\tData() interface{}\n\tNext() Node\n}\n```\n\nA counter is also printed below each node so one doesn't have to manually count them by pointing a finger at the screen. Also, a list can contain a million elements, in which case counting by simply shifting finger on screen might not even be possible.\n\n```\n┌───┐┌───┐┌───┐┌─┐┌────┐┌────┐┌────┐\n│333├┤222├┤111├┤0├┤-111├┤-222├┤-333│\n├───┤├───┤├───┤├─┤├────┤├────┤├────┤\n│  1││  2││  3││4││   5││   6││   7│\n└───┘└───┘└───┘└─┘└────┘└────┘└────┘\n```\n\n### Stacks\n[![stack](https://godoc.org/github.com/shivammg/ppds?status.svg)](https://godoc.org/github.com/shivamMg/ppds/stack)\n\n```\ntype Stack interface {\n\tPop() (ele interface{}, ok bool)\n\tPush(ele interface{})\n}\n```\n\n```\n│ factorial (1) │7│\n│ factorial (2) │6│\n│ factorial (3) │5│\n│ factorial (4) │4│\n│ factorial (5) │3│\n│ factorial (6) │2│\n│ factorial (7) │1│\n└───────────────┴─┘\n```\n\n### Queues\n[![queue](https://godoc.org/github.com/shivammg/ppds?status.svg)](https://godoc.org/github.com/shivamMg/ppds/queue)\n\n```\ntype Queue interface {\n\tPop() (ele interface{}, ok bool)\n\tPush(ele interface{})\n}\n```\n\n```\n ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐\n→│Dec│→│Nov│→│Oct│→│Sep│→│Aug│→│Jul│→│Jun│→│May│→│Apr│→│Mar│→│Feb│→│Jan│→\n ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤\n │  1│ │  2│ │  3│ │  4│ │  5│ │  6│ │  7│ │  8│ │  9│ │ 10│ │ 11│ │ 12│\n └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘\n```\n\n## Notes\n\nPrinting Stacks and Queues requires defining Pop and Push methods. Internally these methods are used to get all elements - first by popping all elements then pushing them back in correct order. Use it with caution since the actual data structure is being modified when printing. After printing it'll be back to its original state. I've discussed why I decided to keep it this way in this [reddit thread](https://redd.it/8pbvrd). If there is no simultaneous read/write while printing, for instance from a different go routine, then you don't need to worry about it. Also, this caveat is only for Stacks and Queues.\n\n## Contribute\n\nBug reports, PRs, feature requests, all are welcome.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshivammg%2Fppds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshivammg%2Fppds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshivammg%2Fppds/lists"}