diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-08-30 15:09:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-30 15:09:15 +0800 |
commit | 8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8 (patch) | |
tree | b9ea30e61b410557cc87aa4d828c4cb3cf771984 /core/utils.go | |
parent | 1f34da04eb9d80648349140eb1442cab87ba5cd8 (diff) | |
download | tangerine-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.tar.gz tangerine-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.tar.zst tangerine-consensus-8cb1d5c4f3f7f93d8b2c54addf5c2caced0a1eb8.zip |
core: tune total ordering performance (#81)
- Replace map with slice
Compared to slice, accessing to map is slower and
the memory usage is inefficient.
Diffstat (limited to 'core/utils.go')
-rw-r--r-- | core/utils.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/core/utils.go b/core/utils.go index d023d2e..6b03f93 100644 --- a/core/utils.go +++ b/core/utils.go @@ -92,3 +92,14 @@ func getMedianTime(block *types.Block) (t time.Time, err error) { return } + +func removeFromSortedIntSlice(xs []int, x int) []int { + indexToRemove := sort.Search(len(xs), func(idx int) bool { + return xs[idx] >= x + }) + if indexToRemove == len(xs) || xs[indexToRemove] != x { + // This value is not found. + return xs + } + return append(xs[:indexToRemove], xs[indexToRemove+1:]...) +} |