Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify code comments #209

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions datastruct/dict/concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (dict *ConcurrentDict) PutIfAbsentWithLock(key string, val interface{}) (re
return 1
}

// PutIfExists puts value if the key is exist and returns the number of inserted key-value
// PutIfExists puts value if the key is existed and returns the number of inserted key-value
func (dict *ConcurrentDict) PutIfExists(key string, val interface{}) (result int) {
if dict == nil {
panic("dict is nil")
Expand Down Expand Up @@ -262,7 +262,7 @@ func (dict *ConcurrentDict) decreaseCount() int32 {
}

// ForEach traversal the dict
// it may not visits new entry inserted during traversal
// it may not visit new entry inserted during traversal
func (dict *ConcurrentDict) ForEach(consumer Consumer) {
if dict == nil {
panic("dict is nil")
Expand Down
2 changes: 1 addition & 1 deletion datastruct/dict/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (dict *SimpleDict) PutIfAbsent(key string, val interface{}) (result int) {
return 1
}

// PutIfExists puts value if the key is exist and returns the number of inserted key-value
// PutIfExists puts value if the key is existed and returns the number of inserted key-value
func (dict *SimpleDict) PutIfExists(key string, val interface{}) (result int) {
_, existed := dict.m[key]
if existed {
Expand Down
6 changes: 3 additions & 3 deletions datastruct/lock/lock_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (locks *Locks) spread(hashCode uint32) uint32 {
panic("dict is nil")
}
tableSize := uint32(len(locks.table))
return (tableSize - 1) & uint32(hashCode)
return (tableSize - 1) & hashCode
}

// Lock obtains exclusive lock for writing
Expand Down Expand Up @@ -90,7 +90,7 @@ func (locks *Locks) toLockIndices(keys []string, reverse bool) []uint32 {
}

// Locks obtains multiple exclusive locks for writing
// invoking Lock in loop may cause dead lock, please use Locks
// invoking Lock in loop may cause deadlock, please use Locks
func (locks *Locks) Locks(keys ...string) {
indices := locks.toLockIndices(keys, false)
for _, index := range indices {
Expand All @@ -100,7 +100,7 @@ func (locks *Locks) Locks(keys ...string) {
}

// RLocks obtains multiple shared locks for reading
// invoking RLock in loop may cause dead lock, please use RLocks
// invoking RLock in loop may cause deadlock, please use RLocks
func (locks *Locks) RLocks(keys ...string) {
indices := locks.toLockIndices(keys, false)
for _, index := range indices {
Expand Down
6 changes: 3 additions & 3 deletions datastruct/sortedset/sortedset.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (sortedSet *SortedSet) GetRank(member string, desc bool) (rank int64) {

// ForEachByRank visits each member which rank within [start, stop), sort by ascending order, rank starts from 0
func (sortedSet *SortedSet) ForEachByRank(start int64, stop int64, desc bool, consumer func(element *Element) bool) {
size := int64(sortedSet.Len())
size := sortedSet.Len()
if start < 0 || start >= size {
panic("illegal start " + strconv.FormatInt(start, 10))
}
Expand All @@ -91,12 +91,12 @@ func (sortedSet *SortedSet) ForEachByRank(start int64, stop int64, desc bool, co
if desc {
node = sortedSet.skiplist.tail
if start > 0 {
node = sortedSet.skiplist.getByRank(int64(size - start))
node = sortedSet.skiplist.getByRank(size - start)
}
} else {
node = sortedSet.skiplist.header.level[0].forward
if start > 0 {
node = sortedSet.skiplist.getByRank(int64(start + 1))
node = sortedSet.skiplist.getByRank(start + 1)
}
}

Expand Down