-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from snonux/develop
Add context awareness to dgrep
- Loading branch information
Showing
29 changed files
with
604 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,10 @@ | ||
*_proprietary.go | ||
<<<<<<< HEAD | ||
cache/ | ||
log/ | ||
tags | ||
======= | ||
/cache/ | ||
/log/ | ||
/cache | ||
/log | ||
/tags | ||
/dtail | ||
/dgrep | ||
/dcat | ||
/dmap | ||
/dserver | ||
>>>>>>> 7ee0121afed3e7cab6457142f70e411020ab2b21 | ||
/bin | ||
serverlist.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package datas | ||
|
||
import "fmt" | ||
|
||
// RBuffer is a simple circular string ring buffer data structure. | ||
type RBuffer struct { | ||
Capacity int | ||
size int | ||
readPos int | ||
writePos int | ||
data []string | ||
} | ||
|
||
// NewRBuffer creates a new string ring buffer. | ||
func NewRBuffer(capacity int) (*RBuffer, error) { | ||
if capacity < 1 { | ||
return nil, fmt.Errorf("RBuffer capacity must not be less than 1") | ||
} | ||
|
||
r := RBuffer{ | ||
Capacity: capacity, | ||
size: capacity + 1, | ||
data: make([]string, capacity+1), | ||
} | ||
|
||
return &r, nil | ||
} | ||
|
||
// Add a value. | ||
func (r *RBuffer) Add(value string) { | ||
r.data[r.writePos] = value | ||
r.writePos = (r.writePos + 1) % r.size | ||
|
||
if r.writePos == r.readPos { | ||
r.readPos = (r.readPos + 1) % r.size | ||
} | ||
} | ||
|
||
// Get a value. | ||
func (r *RBuffer) Get() (string, bool) { | ||
if r.readPos == r.writePos { | ||
// RBuffer is empty. | ||
return "", false | ||
} | ||
|
||
value := r.data[r.readPos] | ||
r.readPos = (r.readPos + 1) % r.size | ||
return value, true | ||
} |
Oops, something went wrong.