Documentation ¶
Overview ¶
Copyright 2023 The acquirecloud Authors
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.
Package iterable contains the definition of the Iterator interface and the containers that may expose the iterator objects to iterate over the container elements.
One of the examples is iterable.Map the hash-table with the functionality of iterating over its elements in the order of the elements were added to the map (FIFO).
Copyright 2023 The acquirecloud Authors ¶
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.
Copyright 2023 The acquirecloud Authors ¶
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.
Copyright 2023 The acquirecloud Authors ¶
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.
Copyright 2023 The acquirecloud Authors ¶
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 EmptyIterator ¶
type EmptyIterator[V any] struct{}
func (*EmptyIterator[V]) Close ¶
func (ei *EmptyIterator[V]) Close() error
func (*EmptyIterator[V]) HasNext ¶
func (ei *EmptyIterator[V]) HasNext() bool
func (*EmptyIterator[V]) Next ¶
func (ei *EmptyIterator[V]) Next() (V, bool)
type Iterator ¶
type Iterator[V any] interface { // HasNext returns true if the collection contains next element for the iterator. Please see Next() function HasNext() bool // Next returns the next element and shifts the iterator to next one if it exists. Second // parameter indicates that the iterator returned a value. This function may return default // value for the type V, if the Next element does not exist (second parameter is false). // // The imparity may be observed between HasNext() and Next() functions results if the // element the iterator was pointing to was the last element and it was removed in between this 2 calls. // This case the HasNext() will return true, but the Next() will returns default values because the element // is deleted. Next() (V, bool) // Close closes the iterator and releases resources. The iterator object must not be used after the call. // The function must be always called for any iterator to release the resources properly. Violating the // contract may cause a memory leak. Close() error }
Iterator interface provides some functions that allow to move over some sorted collection. It has three functions: HasNext(), Next() and Close() that can be used for iterating over the collection elements and releasing resources after usage.
func WrapIntSlice ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map implements a map with an mapIterator capability. The mapIterator allows considering elements from start to end in the order of the elements were added into the map. It is safe to remove and add new elements into the map while an iterator exists, it will support the order the elements were added into the map
func NewMap ¶
func NewMap[K comparable, V any]() *Map[K, V]
NewMap creates the new instance of Map[K, V]
func (*Map[K, V]) Add ¶
Add allows adding new key-value pair into the map. The function returns error if the key already exists in the map
type MapEntry ¶
type MapEntry[K comparable, V any] struct { Key K Value V }
MapEntry implements a record in the Map, which contains Key and the Value for the record
type Mixer ¶
type Mixer[E any] struct { // contains filtered or unexported fields }
Mixer allows to mix 2 Iterators to one. Mixer provides the Iterator interface
func (*Mixer[E]) HasNext ¶
func (mr *Mixer[E]) HasNext() bool
HasNext is the part of the Iterator interface
func (*Mixer[E]) Reset ¶
func (mr *Mixer[E]) Reset() error
Reset allows to reset the mixer internals and retry underlying iterators. This function will also try to reset underlying iterators if they support Resetable interface. If the underlying iterators do not support Reset(), the Reset() will report ErrUnimplemented