Skip to content

Conversation

WolfieLeader
Copy link

Description

This PR optimizes the Set implementation by replacing the bool value with an empty struct (struct{}). This significantly reduces memory usage, especially for large data sets.

Motivation

The Set previously used a map[T]bool, where each value occupied at least one byte. Since the actual value in a Set is irrelevant (presence of a key implies membership), this value can be replaced with an empty struct (struct{}), which has zero memory allocation in Go.

This change enhances memory efficiency without affecting functionality or performance negatively.

Changes

  • Replaced map[T]bool with map[T]struct{} for Set implementation.

Checklist

  • Code compiles and passes tests.
  • Implementation is idiomatic and conforms to Go best practices.
  • Changes are isolated to a single logical unit.
  • File naming and formatting follow repository guidelines.
  • Added or updated tests as necessary.

Copy link

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Aug 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants