fastmap

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Copyright 2025 Stoolap Contributors

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Int64Map

type Int64Map[V any] struct {
	// contains filtered or unexported fields
}

Int64Map is a specialized map for int64 keys. It is specifically optimized for clustered keys, where keys are likely to be close to each other (e.g., sequential IDs, timestamp ranges).

func NewInt64Map

func NewInt64Map[V any](capacity int) *Int64Map[V]

NewInt64Map creates a new Int64Map with given capacity

func (*Int64Map[V]) All

func (m *Int64Map[V]) All() iter.Seq2[int64, V]

All returns an iterator over key-value pairs

func (*Int64Map[V]) Clear

func (m *Int64Map[V]) Clear()

Clear removes all items from the map

func (*Int64Map[V]) Del

func (m *Int64Map[V]) Del(key int64) bool

Del deletes a key and its value

func (*Int64Map[V]) ForEach

func (m *Int64Map[V]) ForEach(f func(int64, V) bool)

ForEach iterates through all key-value pairs

func (*Int64Map[V]) Get

func (m *Int64Map[V]) Get(key int64) (V, bool)

Get retrieves a value by key

func (*Int64Map[V]) Has

func (m *Int64Map[V]) Has(key int64) bool

Has checks if key exists in the map

func (*Int64Map[V]) Keys

func (m *Int64Map[V]) Keys() iter.Seq[int64]

Keys returns an iterator over keys

func (*Int64Map[V]) Len

func (m *Int64Map[V]) Len() int

Len returns the number of elements in the map

func (*Int64Map[V]) Put

func (m *Int64Map[V]) Put(key int64, val V)

Put adds or updates key with value

func (*Int64Map[V]) PutIfNotExists

func (m *Int64Map[V]) PutIfNotExists(key int64, val V) (V, bool)

PutIfNotExists adds key-value pair only if key doesn't exist

func (*Int64Map[V]) Values

func (m *Int64Map[V]) Values() iter.Seq[V]

Values returns an iterator over values

type Pair

type Pair[V any] struct {
	Key   int64
	Value V
}

Pair contains a key-value pair

type SegmentInt64Map

type SegmentInt64Map[V any] struct {
	// contains filtered or unexported fields
}

SegmentInt64Map is a fast, thread-safe map for int64 keys that uses sharding (segmentation) to reduce lock contention while maintaining the performance benefits of Int64Map

func NewSegmentInt64Map

func NewSegmentInt64Map[V any](segmentPower uint8, initialCapacity int) *SegmentInt64Map[V]

NewSegmentInt64Map creates a new segmented map for int64 keys segmentPower controls the number of segments (2^segmentPower) initialCapacity is the initial capacity per segment

func (*SegmentInt64Map[V]) All

func (m *SegmentInt64Map[V]) All() iter.Seq2[int64, V]

All returns an iterator over all key-value pairs

func (*SegmentInt64Map[V]) Clear

func (m *SegmentInt64Map[V]) Clear()

Clear removes all entries from the map

func (*SegmentInt64Map[V]) Del

func (m *SegmentInt64Map[V]) Del(key int64) bool

Del removes a key from the map

func (*SegmentInt64Map[V]) ForEach

func (m *SegmentInt64Map[V]) ForEach(f func(int64, V) bool)

ForEach iterates through all key-value pairs Note: The iteration is not atomic and may miss concurrent updates

func (*SegmentInt64Map[V]) Get

func (m *SegmentInt64Map[V]) Get(key int64) (V, bool)

Get retrieves a value by key

func (*SegmentInt64Map[V]) Has

func (m *SegmentInt64Map[V]) Has(key int64) bool

Has checks if a key exists in the map

func (*SegmentInt64Map[V]) Keys

func (m *SegmentInt64Map[V]) Keys() iter.Seq[int64]

Keys returns an iterator over all keys

func (*SegmentInt64Map[V]) Len

func (m *SegmentInt64Map[V]) Len() int64

Len returns the number of elements in the map

func (*SegmentInt64Map[V]) PutIfNotExists

func (m *SegmentInt64Map[V]) PutIfNotExists(key int64, value V) (V, bool)

PutIfNotExists adds the key-value pair only if the key doesn't already exist Returns the value and true if inserted, or existing value and false if not inserted

func (*SegmentInt64Map[V]) Set

func (m *SegmentInt64Map[V]) Set(key int64, value V)

Set adds or updates a key-value pair

func (*SegmentInt64Map[V]) Values

func (m *SegmentInt64Map[V]) Values() iter.Seq[V]

Values returns an iterator over all values

type SyncInt64Map

type SyncInt64Map[V any] struct {
	// contains filtered or unexported fields
}

SyncInt64Map is a highly optimized map for int64 keys This is the production version incorporating all performance optimizations

func NewSyncInt64Map

func NewSyncInt64Map[V any](sizePower uint) *SyncInt64Map[V]

NewSyncInt64Map creates a new optimized map for int64 keys

func (*SyncInt64Map[V]) All

func (m *SyncInt64Map[V]) All() iter.Seq2[int64, V]

func (*SyncInt64Map[V]) Del

func (m *SyncInt64Map[V]) Del(key int64) bool

Del removes a key from the map

func (*SyncInt64Map[V]) ForEach

func (m *SyncInt64Map[V]) ForEach(f func(int64, V) bool)

ForEach iterates through all key-value pairs

func (*SyncInt64Map[V]) Get

func (m *SyncInt64Map[V]) Get(key int64) (V, bool)

Get retrieves a value by key

func (*SyncInt64Map[V]) Has

func (m *SyncInt64Map[V]) Has(key int64) bool

Has checks if a key exists in the map without retrieving its value

func (*SyncInt64Map[V]) Len

func (m *SyncInt64Map[V]) Len() int64

Len returns the number of elements in the map

func (*SyncInt64Map[V]) Set

func (m *SyncInt64Map[V]) Set(key int64, value V)

Set adds or updates a key-value pair

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL