Skip to content

Commit

Permalink
Add generics support for map (#34)
Browse files Browse the repository at this point in the history
Adds a separate generics Map implementation (MapOf).
  • Loading branch information
vearutop authored Feb 27, 2022
1 parent efd8a81 commit ab3ed40
Show file tree
Hide file tree
Showing 7 changed files with 864 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.16.x, 1.17.x]
go-version: [1.16.x, 1.17.x, 1.18.0-rc1]
name: Build with Go ${{ matrix.go-version }}
steps:
- uses: actions/[email protected]
- name: Install Go
uses: actions/setup-go@v2
with:
stable: false
go-version: ${{ matrix.go-version }}

- name: Install golint
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.16.x]
go-version: [1.18.0-rc1]
name: Build with Go ${{ matrix.go-version }}
steps:
- uses: actions/[email protected]
- name: Install Go
uses: actions/setup-go@v2
with:
stable: false
go-version: ${{ matrix.go-version }}

- name: Run coverage
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ CLHT is built around idea to organize the hash table in cache-line-sized buckets

One important difference with sync.Map is that only string keys are supported. That's because Golang standard library does not expose the built-in hash functions for `interface{}` values.

`MapOf[V]` is an implementation with parametrized value type. It is available for Go 1.18 or later.

```go
m := xsync.NewMapOf[string]()
m.Store("foo", "bar")
v, ok := m.Load("foo")
```

## MPMCQueue

A `MPMCQeueue` is a bounded multi-producer multi-consumer concurrent queue.
Expand Down
12 changes: 12 additions & 0 deletions export_mapof_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build go1.18
// +build go1.18

package xsync

func CollectMapOfStats[V any](m *MapOf[V]) MapStats {
return MapStats{m.stats()}
}

func MapOfSize[V any](m *MapOf[V]) int {
return m.size()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/puzpuzpuz/xsync

go 1.16
go 1.18
Loading

0 comments on commit ab3ed40

Please sign in to comment.