All Projects → shivamMg → Ppds

shivamMg / Ppds

Licence: mit
Pretty Print Data Structures

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Ppds

Floweaver
View flow data as Sankey diagrams
Stars: ✭ 266 (-13.36%)
Mutual labels:  data-structures
Arcus
ARCUS is the NAVER memcached with lists, sets, maps and b+trees. http://naver.github.io/arcus
Stars: ✭ 273 (-11.07%)
Mutual labels:  data-structures
Leetcode 101
LeetCode 101:和你一起你轻松刷题(C++)
Stars: ✭ 5,327 (+1635.18%)
Mutual labels:  data-structures
Python Data Structure Cn
problem-solving-with-algorithms-and-data-structure-using-python 中文版
Stars: ✭ 2,898 (+843.97%)
Mutual labels:  data-structures
Php
All Algorithms implemented in Php
Stars: ✭ 272 (-11.4%)
Mutual labels:  data-structures
Algorithms
My Algorithms and Data Structures studies. https://leandrotk.github.io/series/algorithms-problem-solving
Stars: ✭ 275 (-10.42%)
Mutual labels:  data-structures
Mega Interview Guide
The MEGA interview guide, JavaSciript, Front End, Comp Sci
Stars: ✭ 255 (-16.94%)
Mutual labels:  data-structures
Rubytree
A General Purpose Tree Data Structure for Ruby
Stars: ✭ 300 (-2.28%)
Mutual labels:  data-structures
Data Structures Algorithms
My implementation of 85+ popular data structures and algorithms and interview questions in Python 3 and C++
Stars: ✭ 273 (-11.07%)
Mutual labels:  data-structures
Libgraph
A graph data structure library for Elixir projects
Stars: ✭ 284 (-7.49%)
Mutual labels:  data-structures
Cpp
Repository for C++/C codes and algos.
Stars: ✭ 265 (-13.68%)
Mutual labels:  data-structures
Embeddedsystem
📚 嵌入式系统基础知识与主流编程语言相关内容总结
Stars: ✭ 266 (-13.36%)
Mutual labels:  data-structures
Merkle Patricia Tree
Project is in active development and has been moved to the EthereumJS VM monorepo.
Stars: ✭ 277 (-9.77%)
Mutual labels:  data-structures
Javascript Datastructures Algorithms
📚 collection of JavaScript and TypeScript data structures and algorithms for education purposes. Source code bundle of JavaScript algorithms and data structures book
Stars: ✭ 3,221 (+949.19%)
Mutual labels:  data-structures
Ordered Map
C++ hash map and hash set which preserve the order of insertion
Stars: ✭ 287 (-6.51%)
Mutual labels:  data-structures
Jschema
A simple, easy to use data modeling framework for JavaScript
Stars: ✭ 261 (-14.98%)
Mutual labels:  data-structures
Algae
Bootstrapped algebraic data types for Elixir
Stars: ✭ 272 (-11.4%)
Mutual labels:  data-structures
Data Structure Php Clanguage
对于数据结构和算法类的东西,我工作有些年份了,大学也有所涉猎,积累了一些内容,不高产不母猪,打我自己脸
Stars: ✭ 299 (-2.61%)
Mutual labels:  data-structures
Daily Coding Problem
Solutions for Daily Coding Problem.
Stars: ✭ 300 (-2.28%)
Mutual labels:  data-structures
Dart
Stars: ✭ 278 (-9.45%)
Mutual labels:  data-structures

ppds godoc Build License: MIT

Pretty Print Data Structures

Stacks, 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.

The following data structures are supported:

Trees

tree

A type that satisfies the following interface can be printed using tree.Print.

type Node interface {
	Data() interface{}
	Children() []Node
}
Music
├──────────────────────────────────────────┐
Classical                                  Pop/Rock
├────────────────────┐                     ├───────────────────────────┐
Instrumental         Vocal                 Organic                     Electronic
├──────┐             ├─────────────┐       ├────────────┐              ├────────────────┐
Piano  Orchestra     Opera         Chorus  Rock         Country        Pop              Techno
       ├──────┐      ├─────┐               │            ├────────┐     ├─────────┐      ├────────────┐
       Light  Heavy  Male  Female          Heavy metal  Dancing  Soft  Late pop  Disco  Soft techno  Hard techno

If 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.

Music ┬─ Classical ┬─ Instrumental ┬─ Piano
      │            │               └─ Orchestra ┬─ Light
      │            │                            └─ Heavy
      │            └─ Vocal ┬─ Opera ┬─ Male
      │                     │        └─ Female
      │                     └─ Chorus
      └─ Pop/Rock ┬─ Organic ┬─ Rock ── Heavy metal
                  │          └─ Country ┬─ Dancing
                  │                     └─ Soft
                  └─ Electronic ┬─ Pop ┬─ Late pop
                                │      └─ Disco
                                └─ Techno ┬─ Soft techno
                                          └─ Hard techno

Inspired by 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.

Music
├─ Classical
│  ├─ Instrumental
│  │  ├─ Piano
│  │  └─ Orchestra
│  │     ├─ Light
│  │     └─ Heavy
│  └─ Vocal
│     ├─ Opera
│     │  ├─ Male
│     │  └─ Female
│     └─ Chorus
└─ Pop/Rock
   ├─ Organic
   │  ├─ Rock
   │  │  └─ Heavy metal
   │  └─ Country
   │     ├─ Dancing
   │     └─ Soft
   └─ Electronic
      ├─ Pop
      │  ├─ Late pop
      │  └─ Disco
      └─ Techno
         ├─ Soft techno
         └─ Hard techno

Linked Lists

list

type Node interface {
	Data() interface{}
	Next() Node
}

A 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.

┌───┐┌───┐┌───┐┌─┐┌────┐┌────┐┌────┐
│333├┤222├┤111├┤0├┤-111├┤-222├┤-333│
├───┤├───┤├───┤├─┤├────┤├────┤├────┤
│  1││  2││  3││4││   5││   6││   7│
└───┘└───┘└───┘└─┘└────┘└────┘└────┘

Stacks

stack

type Stack interface {
	Pop() (ele interface{}, ok bool)
	Push(ele interface{})
}
│ factorial (1) │7│
│ factorial (2) │6│
│ factorial (3) │5│
│ factorial (4) │4│
│ factorial (5) │3│
│ factorial (6) │2│
│ factorial (7) │1│
└───────────────┴─┘

Queues

queue

type Queue interface {
	Pop() (ele interface{}, ok bool)
	Push(ele interface{})
}
 ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐ ┌───┐
→│Dec│→│Nov│→│Oct│→│Sep│→│Aug│→│Jul│→│Jun│→│May│→│Apr│→│Mar│→│Feb│→│Jan│→
 ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤ ├───┤
 │  1│ │  2│ │  3│ │  4│ │  5│ │  6│ │  7│ │  8│ │  9│ │ 10│ │ 11│ │ 12│
 └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘ └───┘

Notes

Printing 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. 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.

Contribute

Bug reports, PRs, feature requests, all are welcome.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].