New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/projectdiscovery/hmap

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/projectdiscovery/hmap

  • v0.0.77
  • Source
  • Go
  • Socket score

Version published
Created
Source

hmap

Hybrid memory/disk map that helps you to manage key value storage for input deduplication.


Available functions:

NameDeclaration/Params/Return
Newfunc New(options Options) (*HybridMap, error){}
Closefunc (hm *HybridMap) Close() error{}
Setfunc (hm *HybridMap) Set(k string, v []byte) error{}
Getfunc (hm *HybridMap) Get(k string) ([]byte, bool){}
Delfunc (hm *HybridMap) Del(key string) error{}
Scanfunc (hm *HybridMap) Scan(f func([]byte, []byte) error){}
Sizefunc (hm *HybridMap) Size() int64{}
TuneMemoryfunc (hm *HybridMap) TuneMemory(){}

Available options:

const (
	Memory MapType = iota
	Disk
	Hybrid
)

type DBType int

const (
	LevelDB DBType = iota
	PogrebDB
	BBoltDB
	BuntDB
)
NameProps
DefaultOptions- Type: Memory
- MemoryExpirationTime: time.Duration(5) * time.Minute
- JanitorTime: time.Duration(1) * time.Minute
DefaultMemoryOptions- Type: Memory
DefaultDiskOptions- Type: Disk
- DBType: LevelDB
- Cleanup: true
- RemoveOlderThan: 24* time.Hour *2
DefaultDiskOptions- Type: Hybrid
- DBType: PogrebDB
- MemoryExpirationTime: time.Duration(5) * time.Minute
- JanitorTime: time.Duration(1) * time.Minute

Custom options:

type Options struct {
	MemoryExpirationTime time.Duration
	DiskExpirationTime   time.Duration
	JanitorTime          time.Duration
	Type                 MapType
	DBType               DBType
	MemoryGuardForceDisk bool
	MemoryGuard          bool
	MaxMemorySize        int
	MemoryGuardTime      time.Duration
	Path                 string
	Cleanup              bool
	Name                 string
	RemoveOlderThan time.Duration
}

Simple usage example

func main() {
	var wg sync.WaitGroup
	wg.Add(1)
	go normal(&wg)
	wg.Wait()
}

func normal(wg *sync.WaitGroup) {
	defer wg.Done()
	hm, err := hybrid.New(hybrid.DefaultOptions)
	if err != nil {
		log.Fatal(err)
	}
	defer hm.Close()
	err2 := hm.Set("a", []byte("b"))
	if err2 != nil {
		log.Fatal(err2)
	}
	v, ok := hm.Get("a")
	if ok {
		log.Println(v)
	}
}

License

hmap is distributed under MIT License

FAQs

Package last updated on 20 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc