2025-10-11 07:46:29 +07:00
2025-10-10 19:56:42 -04:00
2025-10-11 07:46:29 +07:00
2025-10-10 19:56:42 -04:00
2025-10-11 07:46:29 +07:00
2025-10-11 07:46:29 +07:00

safe-map

A thread-safe map implementation for Go with simple API and full concurrency support.

Features

  • Thread-safe operations
  • Generic type support
  • Simple and intuitive API
  • Full concurrency support
  • Lightweight implementation

Installation

go get git.neurocipta.com/rogerferdinan/safe-map

Usage

package main

import (
    "fmt"
    "log"
    safemap "git.neurocipta.com/rogerferdinan/safe-map"
)

func main() {
    // Create a new SafeMap with string keys and int values
    m := safemap.NewSafeMap[string, int]()
    
    // Store data to SafeMap
    m.Store("abc", 1) // Add
    m.Store("abc", 2) // Update existing key-value
    
    // Get length of SafeMap
    length := m.Len()
    fmt.Printf("Map length: %d\n", length)
    
    // Load key-value
    value, ok := m.Load("abc")
    if !ok {
        log.Fatal("abc is not exists")
    }
    fmt.Printf("Value for 'abc': %v\n", value)
    
    // Iterate over all key-value pairs
    m.Range(func(k string, v int) bool {
        fmt.Printf("key: %s, value: %v\n", k, v)
        return true // true = continue the loop, false = break the loop
    })
    
    // Delete key-value
    m.Delete("abc")
}

Thread Safety

All operations are thread-safe and can be safely called from multiple goroutines simultaneously.

Description
No description provided
Readme Apache-2.0 29 KiB
Languages
Go 100%