data-structures

module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2025 License: MIT

README ΒΆ

Data Structures and Algorithms in Go

This repository contains implementations of various data structures and algorithms in Go programming language. It serves as both a learning resource and a practical reference for developers.

πŸ“š Data Structures

Basic Data Structures
  • Linked List
    • Singly Linked List
    • Doubly Linked List
    • Circular Linked List
  • Stack
    • Array-based implementation
    • Linked List-based implementation
  • Queue
    • Simple Queue
    • Priority Queue
    • Circular Queue
  • Tree
    • Binary Tree
    • Binary Search Tree (BST)
    • AVL Tree
  • Heap
    • Min Heap
    • Max Heap
  • Hash
    • Hash Table
    • Hash Map implementations
  • OrderedMap
    • Thread-safe implementation
    • Order preservation
    • Concurrent operations support
    • Advanced features (Copy, Clear, Range iteration)
Advanced Data Structures
  • Graph
    • Adjacency Matrix
    • Adjacency List
    • Graph Algorithms
      • Depth First Search (DFS)
      • Breadth First Search (BFS)
      • Topological Sort
      • Shortest Path Algorithms

πŸ”§ Algorithms

Sorting Algorithms
  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Quick Sort
  • Merge Sort
  • Heap Sort
Searching Algorithms
  • Linear Search
  • Binary Search
  • Interpolation Search

πŸš€ Getting Started

Prerequisites
  • Go 1.23 or higher
Installation
git clone https://github.com/mstgnz/data-structures.git
cd data-structures
go mod download
Running Tests
go test ./...

πŸ“– Usage Examples

You can find example implementations in the examples directory. Each data structure and algorithm includes its own test files demonstrating usage patterns.

// Example: Creating and using a Binary Search Tree
import "github.com/mstgnz/data-structures/tree"

bst := tree.NewBST()
bst.Insert(5)
bst.Insert(3)
bst.Insert(7)
// Example: Using OrderedMap with thread-safety and order preservation
import "github.com/mstgnz/data-structures/orderedmap"

om := orderedmap.New()

// Adding elements (order is preserved)
om.Set("first", 1)
om.Set("second", 2)
om.Set("third", 3)

// Reading values
if val, exists := om.Get("second"); exists {
    fmt.Printf("Value: %v\n", val)
}

// Iterating in order
om.Range(func(key, value any) bool {
    fmt.Printf("%v: %v\n", key, value)
    return true
})

// Thread-safe operations
go func() {
    om.Set("concurrent", 42)
}()

🀝 Contributing

Contributions are welcome! Please read our Contributing Guidelines for details on how to submit pull requests.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ” Project Structure

.
β”œβ”€β”€ algorithms/    # Basic algorithm implementations
β”œβ”€β”€ advanced/      # Advanced data structures
β”œβ”€β”€ examples/      # Usage examples
β”œβ”€β”€ graph/         # Graph implementations
β”œβ”€β”€ hash/          # Hash table implementations
β”œβ”€β”€ heap/          # Heap implementations
β”œβ”€β”€ linkedlist/    # Linked list implementations
β”œβ”€β”€ queue/         # Queue implementations
β”œβ”€β”€ stack/         # Stack implementations
β”œβ”€β”€ tree/          # Tree implementations
└── utils/         # Utility functions

✨ Features

  • Clean and efficient implementations
  • Comprehensive test coverage
  • Well-documented code
  • Generic implementations where applicable
  • Performance optimized
  • Thread-safe implementations where necessary
  • Order preservation in map operations
  • Concurrent access support with proper synchronization
  • Advanced data structure features (Copy, Clear, Range operations)

πŸ“Š Performance

Each implementation includes performance considerations and Big O notation analysis in its respective documentation.

πŸ”„ Version History

See CHANGELOG.md for release history and version details.

Directories ΒΆ

Path Synopsis
examples
graph command
hash command
heap command
linkedlist command
orderedmap command
queue command
stack command
tree command
Package heap implements various heap data structures
Package heap implements various heap data structures

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL