Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
c2d1b2f9
Commit
c2d1b2f9
authored
5 years ago
by
Wolfgang Welz
Browse files
Options
Downloads
Patches
Plain Diff
Add ForEachWithPrefix database function
parent
1b10d910
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
go.sum
+1
-0
1 addition, 0 deletions
go.sum
packages/database/database.go
+10
-2
10 additions, 2 deletions
packages/database/database.go
packages/database/interfaces.go
+2
-1
2 additions, 1 deletion
packages/database/interfaces.go
with
13 additions
and
3 deletions
go.sum
+
1
−
0
View file @
c2d1b2f9
...
@@ -43,6 +43,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
...
@@ -43,6 +43,7 @@ github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T
github.com/hpcloud/tail
v1.0.0 h1:
nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail
v1.0.0 h1:
nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail
v1.0.0/go.mod h1:
ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hpcloud/tail
v1.0.0/go.mod h1:
ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap
v1.0.0/go.mod h1:
PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap
v1.0.0/go.mod h1:
PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/iotaledger/iota.go
v1.0.0-beta.7 h1:
OaUNahPvOdQz2nKcgeAfcUdxlEDlEV3xwLIkwzZ1B/U=
github.com/iotaledger/iota.go
v1.0.0-beta.7/go.mod h1:
dMps6iMVU1pf5NDYNKIw4tRsPeC8W3ZWjOvYHOO1PMg=
github.com/iotaledger/iota.go
v1.0.0-beta.7/go.mod h1:
dMps6iMVU1pf5NDYNKIw4tRsPeC8W3ZWjOvYHOO1PMg=
github.com/kr/pretty
v0.1.0 h1:
L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty
v0.1.0 h1:
L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty
v0.1.0/go.mod h1:
dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty
v0.1.0/go.mod h1:
dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
...
...
This diff is collapsed.
Click to expand it.
packages/database/database.go
+
10
−
2
View file @
c2d1b2f9
...
@@ -100,10 +100,10 @@ func (this *prefixDb) Delete(key []byte) error {
...
@@ -100,10 +100,10 @@ func (this *prefixDb) Delete(key []byte) error {
return
err
return
err
}
}
func
(
this
*
prefixDb
)
F
orEach
(
consumer
func
([]
byte
,
[]
byte
))
error
{
func
(
this
*
prefixDb
)
f
orEach
(
prefix
[]
byte
,
consumer
func
([]
byte
,
[]
byte
))
error
{
err
:=
this
.
db
.
View
(
func
(
txn
*
badger
.
Txn
)
error
{
err
:=
this
.
db
.
View
(
func
(
txn
*
badger
.
Txn
)
error
{
iteratorOptions
:=
badger
.
DefaultIteratorOptions
iteratorOptions
:=
badger
.
DefaultIteratorOptions
iteratorOptions
.
Prefix
=
this
.
prefix
// filter by prefix
iteratorOptions
.
Prefix
=
prefix
// filter by prefix
// create an iterator the default options
// create an iterator the default options
it
:=
txn
.
NewIterator
(
iteratorOptions
)
it
:=
txn
.
NewIterator
(
iteratorOptions
)
...
@@ -124,3 +124,11 @@ func (this *prefixDb) ForEach(consumer func([]byte, []byte)) error {
...
@@ -124,3 +124,11 @@ func (this *prefixDb) ForEach(consumer func([]byte, []byte)) error {
})
})
return
err
return
err
}
}
func
(
this
*
prefixDb
)
ForEachWithPrefix
(
prefix
[]
byte
,
consumer
func
([]
byte
,
[]
byte
))
error
{
return
this
.
forEach
(
append
(
this
.
prefix
,
prefix
...
),
consumer
)
}
func
(
this
*
prefixDb
)
ForEach
(
consumer
func
([]
byte
,
[]
byte
))
error
{
return
this
.
forEach
(
this
.
prefix
,
consumer
)
}
This diff is collapsed.
Click to expand it.
packages/database/interfaces.go
+
2
−
1
View file @
c2d1b2f9
...
@@ -7,6 +7,7 @@ type Database interface {
...
@@ -7,6 +7,7 @@ type Database interface {
SetWithTTL
(
key
[]
byte
,
value
[]
byte
,
ttl
time
.
Duration
)
error
SetWithTTL
(
key
[]
byte
,
value
[]
byte
,
ttl
time
.
Duration
)
error
Contains
(
key
[]
byte
)
(
bool
,
error
)
Contains
(
key
[]
byte
)
(
bool
,
error
)
Get
(
key
[]
byte
)
([]
byte
,
error
)
Get
(
key
[]
byte
)
([]
byte
,
error
)
ForEach
(
func
(
key
[]
byte
,
value
[]
byte
))
error
ForEach
(
consumer
func
(
key
[]
byte
,
value
[]
byte
))
error
ForEachWithPrefix
(
prefix
[]
byte
,
consumer
func
(
key
[]
byte
,
value
[]
byte
))
error
Delete
(
key
[]
byte
)
error
Delete
(
key
[]
byte
)
error
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment