Skip to content

Suggestion: Add PopN(n int) ([]T, int) #165

@lazychanger

Description

@lazychanger

When using threadSafeSet for batch Pop, the overhead caused by RWMutex can be reduced.

func (s *threadUnsafeSet[T])PopN(n int)([]T, int) {
  suc := 0
  ss := make([]T, 0, n)
  for item := range *s {
    ss = append(ss, item)
    delete(*s, item)
    suc += 1
    if suc >= n {
      return  ss, suc
    }
  }
  return ss, suc
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions