Documentation ¶
Overview ¶
Package stl4go is a generic container and algorithm library for go.
Index ¶
- func AllOf[T any](a []T, pred func(T) bool) bool
- func AnyOf[T any](a []T, pred func(T) bool) bool
- func Average[T Numeric](a []T) T
- func AverageAs[R, T Numeric](a []T) R
- func BinarySearch[T Ordered](a []T, value T) (index int, ok bool)
- func BinarySearchFunc[T any](a []T, value T, less LessFn[T]) (index int, ok bool)
- func Compare[E Ordered](a, b []E) int
- func Copy[T any](a []T) []T
- func Count[T comparable](a []T, x T) int
- func CountIf[T comparable](a []T, pred func(T) bool) int
- func DescSort[T Ordered](a []T)
- func DescStableSort[T Ordered](a []T)
- func Equal[T comparable](a, b []T) bool
- func Equals[T comparable](a, b T) bool
- func Find[T comparable](a []T, x T) (index int, ok bool)
- func FindIf[T any](a []T, cond func(T) bool) (index int, ok bool)
- func Generate[T any](a []T, gen func() T)
- func Index[T comparable](a []T, x T) int
- func IsDescSorted[T Ordered](a []T) bool
- func IsSorted[T Ordered](a []T) bool
- func Less[T Ordered](a, b T) bool
- func LowerBound[T Ordered](a []T, value T) int
- func LowerBoundFunc[T any](a []T, value T, less LessFn[T]) int
- func Max[T Ordered](a, b T) T
- func MaxN[T Ordered](a ...T) T
- func Min[T Ordered](a, b T) T
- func MinMax[T Ordered](a, b T) (min, max T)
- func MinMaxN[T Ordered](a ...T) (min, max T)
- func MinN[T Ordered](a ...T) T
- func NoneOf[T any](a []T, pred func(T) bool) bool
- func OrderedCompare[T Ordered](a, b T) int
- func Range[T Numeric](first, last T) []T
- func Remove[T comparable](a []T, x T) []T
- func RemoveCopy[T comparable](a []T, x T) []T
- func RemoveIf[T any](a []T, cond func(T) bool) []T
- func RemoveIfCopy[T any](a []T, cond func(T) bool) []T
- func Reverse[T any](a []T)
- func ReverseCopy[T any](a []T) []T
- func Shuffle[T any](a []T)
- func Sort[T Ordered](a []T)
- func SortFunc[T any](a []T, less func(x, y T) bool)
- func StableSort[T Ordered](a []T)
- func StableSortFunc[T any](a []T, less func(x, y T) bool)
- func Sum[T Numeric](a []T) T
- func SumAs[R, T Numeric](a []T) R
- func Transform[T any](a []T, op func(T) T)
- func TransformCopy[R any, T any](a []T, op func(T) R) []R
- func TransformTo[R any, T any](a []T, op func(T) R, b []R)
- func Unique[T comparable](a []T) []T
- func UniqueCopy[T comparable](a []T) []T
- func UpperBound[T Ordered](a []T, value T) int
- func UpperBoundFunc[T any](a []T, value T, less LessFn[T]) int
- type BuiltinSet
- func (s *BuiltinSet[K]) Clear()
- func (s *BuiltinSet[K]) ForEach(cb func(k K))
- func (s *BuiltinSet[K]) ForEachIf(cb func(k K) bool)
- func (s *BuiltinSet[K]) Has(k K) bool
- func (s *BuiltinSet[K]) Insert(k K)
- func (s *BuiltinSet[K]) InsertN(ks ...K)
- func (s *BuiltinSet[K]) IsEmpty() bool
- func (s *BuiltinSet[K]) Keys() []K
- func (s *BuiltinSet[K]) Len() int
- func (s *BuiltinSet[K]) Remove(k K) bool
- func (s *BuiltinSet[K]) RemoveN(ks ...K)
- func (s BuiltinSet[K]) String() string
- type CompareFn
- type Container
- type DList
- func (l *DList[T]) Clear()
- func (l *DList[T]) ForEach(cb func(val T))
- func (l *DList[T]) ForEachIf(cb func(val T) bool)
- func (l *DList[T]) IsEmpty() bool
- func (l *DList[T]) Iterate() Iterator[T]
- func (l *DList[T]) Len() int
- func (l *DList[T]) PopBack() (T, bool)
- func (l *DList[T]) PopFront() (T, bool)
- func (l *DList[T]) PushBack(val T)
- func (l *DList[T]) PushFront(val T)
- func (l *DList[T]) String() string
- type Float
- type HashFn
- type Integer
- type Iterator
- type LessFn
- type Map
- type MapIterator
- type Numeric
- type Ordered
- type Queue
- type Set
- type Signed
- type SkipList
- func (sl *SkipList[K, V]) Clear()
- func (sl *SkipList[K, V]) Find(key K) *V
- func (sl *SkipList[K, V]) FindRange(first, last K) MapIterator[K, V]
- func (sl *SkipList[K, V]) ForEach(op func(K, V))
- func (sl *SkipList[K, V]) ForEachIf(op func(K, V) bool)
- func (sl *SkipList[K, V]) ForEachMutable(op func(K, *V))
- func (sl *SkipList[K, V]) ForEachMutableIf(op func(K, *V) bool)
- func (sl *SkipList[K, V]) Has(key K) bool
- func (sl *SkipList[K, V]) Insert(key K, value V)
- func (sl *SkipList[K, V]) IsEmpty() bool
- func (sl *SkipList[K, V]) Iterate() MapIterator[K, V]
- func (sl *SkipList[K, V]) Len() int
- func (sl *SkipList[K, V]) LowerBound(key K) MapIterator[K, V]
- func (sl *SkipList[K, V]) Remove(key K) bool
- func (sl *SkipList[K, V]) UpperBound(key K) MapIterator[K, V]
- type Stack
- type Unsigned
- type Vector
- func (v *Vector[T]) Append(x ...T)
- func (v *Vector[T]) At(i int) T
- func (v *Vector[T]) Cap() int
- func (v *Vector[T]) Clear()
- func (v *Vector[T]) Insert(i int, x ...T)
- func (v *Vector[T]) IsEmpty() bool
- func (v *Vector[T]) Len() int
- func (v *Vector[T]) PushBack(x T)
- func (v *Vector[T]) Remove(i int)
- func (v *Vector[T]) RemoveLength(i int, len int)
- func (v *Vector[T]) RemoveRange(i, j int)
- func (v *Vector[T]) Reserve(l int)
- func (v *Vector[T]) Set(i int, x T)
- func (v *Vector[T]) Shrink()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllOf ¶
AllOf return true if pred(e) returns true for all emements e in a.
Complexity: O(len(a)).
func AnyOf ¶
AnyOf return true if pred(e) returns true for any emements e in a.
Complexity: O(len(a)).
func AverageAs ¶
func AverageAs[R, T Numeric](a []T) R
AverageAs returns the average value of a as type R.
func BinarySearch ¶
BinarySearch returns the (index, true) to the first element in the ascending ordered slice a such that element == value, or (-1, false) if no such element is found.
Complexity: O(log(len(a))).
func BinarySearchFunc ¶
BinarySearchFunc returns the (index, true) to the first element in the ordered slice a such that less(element, value) and less(value, element) are both false, or (-1, false) if no such element is found.
The elements in the slice a should sorted according with compare func less.
Complexity: O(log(len(a))).
func Compare ¶
Compare compares each elements in a and b.
return 0 if they are equals, return 1 if a > b, return -1 if a < b.
Complexity: O(min(len(a), len(b))).
func Count ¶
func Count[T comparable](a []T, x T) int
Count returns the number of elements in the slice equals to x.
Complexity: O(len(a)).
func CountIf ¶
func CountIf[T comparable](a []T, pred func(T) bool) int
CountIf returns the number of elements in the slice which pred returns true.
Complexity: O(len(a)).
func DescSort ¶
func DescSort[T Ordered](a []T)
DescSort sorts data in descending order. The order of equal elements is not guaranteed to be preserved.
Complexity: O(N*log(N)), N=len(a).
func DescStableSort ¶
func DescStableSort[T Ordered](a []T)
DescStableSort sorts data in descending order stably. The order of equivalent elements is guaranteed to be preserved.
Complexity: O(N*log(N)), N=len(a).
func Equal ¶
func Equal[T comparable](a, b []T) bool
Equal returns whether two slices are equal. Return true if they are the same length and all elements are equal.
Complexity: O(min(len(a), len(b))).
func Equals ¶
func Equals[T comparable](a, b T) bool
Equals wraps the '==' operator for comparable types.
func Find ¶
func Find[T comparable](a []T, x T) (index int, ok bool)
Find find the first value x in the given slice a linearly. return (index, true) if found, return (_, false) if not found.
Complexity: O(len(a)).
func FindIf ¶
FindIf find the first value x satisfying function cond in the given slice a linearly. return (index, true) if found, return (_, false) if not found.
Complexity: O(len(a)).
func Generate ¶
func Generate[T any](a []T, gen func() T)
Generate fill each element of `a“ with `gen()`.
Complexity: O(len(a)).
func Index ¶
func Index[T comparable](a []T, x T) int
Index find the value x in the given slice a linearly.
Return index if found, -1 if not found.
Complexity: O(len(a)).
func IsDescSorted ¶
IsDescSorted returns whether the slice a is sorted in descending order.
Complexity: O(len(a)).
func IsSorted ¶
IsSorted returns whether the slice a is sorted in ascending order.
Complexity: O(len(a)).
func LowerBound ¶
LowerBound returns an index to the first element in the ascending ordered slice a that does not satisfy element < value (i.e. greater or equal to), or len(a) if no such element is found.
Complexity: O(log(len(a))).
func LowerBoundFunc ¶
LowerBoundFunc returns an index to the first element in the ordered slice a that does not satisfy less(element, value)), or len(a) if no such element is found.
The elements in the slice a should sorted according with compare func less.
Complexity: O(log(len(a))).
func Max ¶
func Max[T Ordered](a, b T) T
Max return the larger value between `a` and `b`.
Complexity: O(1).
func MaxN ¶
func MaxN[T Ordered](a ...T) T
MaxN return the maximum value in the sequence `a`.
Complexity: O(len(a)).
func Min ¶
func Min[T Ordered](a, b T) T
Min return the smaller value between `a` and `b`.
Complexity: O(1).
func MinMax ¶
func MinMax[T Ordered](a, b T) (min, max T)
MinMax returns both min and max between a and b.
Complexity: O(1).
func MinMaxN ¶
func MinMaxN[T Ordered](a ...T) (min, max T)
MinMaxN returns both min and max in slice a.
Complexity: O(len(a))
func MinN ¶
func MinN[T Ordered](a ...T) T
MinN return the minimum value in the sequence `a`.
Complexity: O(len(a)).
func NoneOf ¶
NoneOf return true pred(e) returns true for none emements e in a.
Complexity: O(len(a)).
func OrderedCompare ¶
OrderedCompare provide default CompareFn for ordered types.
func Range ¶
func Range[T Numeric](first, last T) []T
Range make a []T filled with values in the `[first, last)` sequence. NOTE: the last is not included in the result.
Complexity: O(last-first).
func Remove ¶
func Remove[T comparable](a []T, x T) []T
Remove remove the elements which equals to x from the input slice. return the processed slice, and the content of the input slice is also changed.
Complexity: O(len(a)).
func RemoveCopy ¶
func RemoveCopy[T comparable](a []T, x T) []T
RemoveCopy remove all elements which equals to x from the input slice. return the processed slice, and the content of the input slice is also changed.
Complexity: O(len(a)).
func RemoveIf ¶
RemoveIf remove each element which make cond(x) returns true from the input slice, copy other elements to a new slice and return it. The input slice is kept unchanged.
Complexity: O(len(a)).
func RemoveIfCopy ¶
RemoveIfCopy drops each element which make cond(x) returns true from the input slice, copy other elements to a new slice and return it. The input slice is kept unchanged.
Complexity: O(len(a)).
func Reverse ¶
func Reverse[T any](a []T)
Reverse reverses the order of the elements in the slice a.
Complexity: O(len(a)).
func ReverseCopy ¶
func ReverseCopy[T any](a []T) []T
ReverseCopy returns a reversed copy of slice a.
Complexity: O(len(a)).
func Shuffle ¶
func Shuffle[T any](a []T)
Shuffle pseudo-randomizes the order of elements.
Complexity: O(len(a)).
func Sort ¶
func Sort[T Ordered](a []T)
Sort sorts data in ascending order. The order of equal elements is not guaranteed to be preserved.
Complexity: O(N*log(N)), where N=len(a).
func SortFunc ¶
SortFunc sorts data in ascending order with compare func less. The order of equal elements is not guaranteed to be preserved.
Complexity: O(N*log(N)), N=len(a).
func StableSort ¶
func StableSort[T Ordered](a []T)
StableSort sorts data in ascending order stably. The order of equivalent elements is guaranteed to be preserved.
Complexity: O(N*log(N)^2), where N=len(a).
func StableSortFunc ¶
StableSortFunc sorts data in ascending order with compare func less stably. The order of equivalent elements is guaranteed to be preserved.
Complexity: O(N*log(N)), N=len(a).
func Sum ¶
func Sum[T Numeric](a []T) T
Sum summarize all elements in a. returns the result as type R, you should use SumAs if T can't hold the result. Complexity: O(len(a)).
func SumAs ¶
func SumAs[R, T Numeric](a []T) R
SumAs summarize all elements in a. returns the result as type R, this is useful when T is too small to hold the result. Complexity: O(len(a)).
func Transform ¶
func Transform[T any](a []T, op func(T) T)
Transform applies the function op to each element in slice a and set it back to the same place in a.
Complexity: O(len(a)).
func TransformCopy ¶
TransformCopy applies the function op to each element in slice a and return all the result as a slice.
Complexity: O(len(a)).
func TransformTo ¶
TransformTo applies the function op to each element in slice a and fill it to slice b.
The len(b) must not lesser than len(a).
Complexity: O(len(a)).
func Unique ¶
func Unique[T comparable](a []T) []T
Unique remove adjacent repeated elements from the input slice. return the processed slice, and the content of the input slice is also changed.
Complexity: O(len(a)).
func UniqueCopy ¶
func UniqueCopy[T comparable](a []T) []T
UniqueCopy remove adjacent repeated elements from the input slice. return the result slice, and the input slice is kept unchanged.
Complexity: O(len(a)).
func UpperBound ¶
UpperBound returns an index to the first element in the ascending ordered slice a such that value < element (i.e. strictly greater), or len(a) if no such element is found.
Complexity: O(log(len(a))).
func UpperBoundFunc ¶
UpperBoundFunc returns an index to the first element in the ordered slice a such that less(value, element)) is true (i.e. strictly greater), or len(a) if no such element is found.
The elements in the slice a should sorted according with compare func less.
Complexity: O(log(len(a))).
Types ¶
type BuiltinSet ¶
type BuiltinSet[K comparable] map[K]bool
BuiltinSet is an associative container that contains a unordered set of unique objects of type K.
func MakeBuiltinSetOf ¶
func MakeBuiltinSetOf[K comparable](ks ...K) BuiltinSet[K]
MakeBuiltinSetOf creates a new BuiltinSet object with the initial content from ks.
func (*BuiltinSet[K]) Clear ¶
func (s *BuiltinSet[K]) Clear()
Clear implements the Container interface.
func (*BuiltinSet[K]) ForEach ¶
func (s *BuiltinSet[K]) ForEach(cb func(k K))
ForEach implements the Set interface.
func (*BuiltinSet[K]) ForEachIf ¶
func (s *BuiltinSet[K]) ForEachIf(cb func(k K) bool)
ForEachIf implements the Container interface.
func (*BuiltinSet[K]) Insert ¶
func (s *BuiltinSet[K]) Insert(k K)
Insert implements the Set interface.
func (*BuiltinSet[K]) InsertN ¶
func (s *BuiltinSet[K]) InsertN(ks ...K)
InsertN implements the Set interface.
func (*BuiltinSet[K]) IsEmpty ¶
func (s *BuiltinSet[K]) IsEmpty() bool
IsEmpty implements the Container interface.
func (*BuiltinSet[K]) Keys ¶
func (s *BuiltinSet[K]) Keys() []K
Keys return a copy of all keys as a slice.
func (*BuiltinSet[K]) Len ¶
func (s *BuiltinSet[K]) Len() int
Len implements the Container interface.
func (*BuiltinSet[K]) Remove ¶
func (s *BuiltinSet[K]) Remove(k K) bool
Remove implements the Set interface.
func (*BuiltinSet[K]) RemoveN ¶
func (s *BuiltinSet[K]) RemoveN(ks ...K)
RemoveN implements the Set interface.
func (BuiltinSet[K]) String ¶
func (s BuiltinSet[K]) String() string
String implements the fmt.Stringer interface
type CompareFn ¶
CompareFn is a 3 way compare function that returns 1 if a > b, returns 0 if a == b, returns -1 if a < b.
type Container ¶
type Container interface { IsEmpty() bool // IsEmpty checks if the container has no elements. Len() int // Len returns the number of elements in the container. Clear() // Clear erases all elements from the container. After this call, Len() returns zero. }
Container is a holder object that stores a collection of other objects.
type DList ¶
type DList[T any] struct { // contains filtered or unexported fields }
DList is a doubly linked list.
func NewDListOf ¶
NewDListOf make a new DList from a serial of values
func (*DList[T]) ForEach ¶
func (l *DList[T]) ForEach(cb func(val T))
ForEach iterate the list, apply each element to the cb callback function
func (*DList[T]) ForEachIf ¶
ForEachIf iterate the list, apply each element to the cb callback function, stop if cb returns false.
func (*DList[T]) Iterate ¶ added in v0.1.1
Iterate returns an iterator to the first element in the list.
func (*DList[T]) PushBack ¶
func (l *DList[T]) PushBack(val T)
PushBack pushes an element at the back of the list.
type Float ¶
Float is a constraint that permits any floating-point type. If future releases of Go add new predeclared floating-point types, this constraint will be modified to include them.
type Integer ¶
Integer is a constraint that permits any integer type. If future releases of Go add new predeclared integer types, this constraint will be modified to include them.
type Iterator ¶ added in v0.1.1
type Iterator[T any] interface { IsNotEnd() bool // Whether it is point to the end of the range. MoveToNext() // Let it point to the next element. Value() T // Return the value of current element. }
Iterator is the interface for container's iterator.
type Map ¶
type Map[K any, V any] interface { Container Has(K) bool // Checks whether the container contains element with specific key. Find(K) *V // Finds element with specific key. Insert(K, V) // Inserts a key-value pair in to the container or replace existing value. Remove(K) bool // Remove element with specific key. ForEach(func(K, V)) // Iterate the container. ForEachIf(func(K, V) bool) // Iterate the container, stops when the callback returns false. ForEachMutable(func(K, *V)) // Iterate the container, *V is mutable. ForEachMutableIf(func(K, *V) bool) // Iterate the container, *V is mutable, stops when the callback returns false. }
Map is a associative container that contains key-value pairs with unique keys.
type MapIterator ¶ added in v0.1.1
MapIterator is the interface for map's iterator.
type Ordered ¶
Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
Queue is a FIFO container
func (*Queue[T]) PushBack ¶
func (q *Queue[T]) PushBack(val T)
PushBack pushed an element to the back of the queue.
type Set ¶
type Set[K any] interface { Container Has(K) bool // Checks whether the container contains element with specific key. Insert(K) // Inserts a key-value pair in to the container or replace existing value. InsertN(...K) // Inserts multiple key-value pairs in to the container or replace existing value. Remove(K) bool // Remove element with specific key. RemoveN(...K) // Remove multiple elements with specific keys. ForEach(func(K)) // Iterate the container. ForEachIf(func(K) bool) // Iterate the container, stops when the callback returns false. }
Set is a containers that store unique elements.
type Signed ¶
Signed is a constraint that permits any signed integer type. If future releases of Go add new predeclared signed integer types, this constraint will be modified to include them.
type SkipList ¶
SkipList is a probabilistic data structure that seem likely to supplant balanced trees as the implementation method of choice for many applications. Skip list algorithms have the same asymptotic expected time bounds as balanced trees and are simpler, faster and use less space.
See https://en.wikipedia.org/wiki/Skip_list for more details.
func NewSkipList ¶
NewSkipList creates a new SkipList for Ordered key type.
func NewSkipListFromMap ¶
NewSkipListFromMap creates a new SkipList from a map.
func NewSkipListFunc ¶
NewSkipListFunc creates a new SkipList with specified compare function keyCmp.
func (*SkipList[K, V]) Clear ¶
func (sl *SkipList[K, V]) Clear()
Clear implements the Container interface.
func (*SkipList[K, V]) Find ¶
func (sl *SkipList[K, V]) Find(key K) *V
Find returns the value associated with the passed key if the key is in the skiplist, otherwise returns nil.
func (*SkipList[K, V]) FindRange ¶ added in v0.1.1
func (sl *SkipList[K, V]) FindRange(first, last K) MapIterator[K, V]
FindRange returns an iterator in range [first, last) (last is not includeed).
func (*SkipList[K, V]) ForEach ¶
func (sl *SkipList[K, V]) ForEach(op func(K, V))
ForEach implements the Map interface.
func (*SkipList[K, V]) ForEachMutable ¶
func (sl *SkipList[K, V]) ForEachMutable(op func(K, *V))
ForEachMutable implements the Map interface.
func (*SkipList[K, V]) ForEachMutableIf ¶
ForEachMutableIf implements the Map interface.
func (*SkipList[K, V]) Insert ¶
func (sl *SkipList[K, V]) Insert(key K, value V)
Insert inserts a key-value pair into the skiplist. If the key is already in the skip list, it's value will be updated.
func (*SkipList[K, V]) Iterate ¶ added in v0.1.1
func (sl *SkipList[K, V]) Iterate() MapIterator[K, V]
Iterate return an iterator to the skiplist.
func (*SkipList[K, V]) LowerBound ¶ added in v0.1.1
func (sl *SkipList[K, V]) LowerBound(key K) MapIterator[K, V]
LowerBound returns an iterator to the first element in the skiplist that does not satisfy element < value (i.e. greater or equal to), or a end itetator if no such element is found.
func (*SkipList[K, V]) Remove ¶
Remove removes the key-value pair associated with the passed key and returns true if the key is in the skiplist, otherwise returns false.
func (*SkipList[K, V]) UpperBound ¶ added in v0.1.1
func (sl *SkipList[K, V]) UpperBound(key K) MapIterator[K, V]
UpperBound returns an iterator to the first element in the skiplist that does not satisfy value < element (i.e. strictly greater), or a end itetator if no such element is found.
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack s is a container adaptor that provides the functionality of a stack, a LIFO (last-in, first-out) data structure.
func NewStackCap ¶
NewStackCap creates a new Stack object with the specified capicity.
func (*Stack[T]) MustPop ¶
func (s *Stack[T]) MustPop() T
MustPop popups an element from the top of the stack. It must be called whtn IsEmpty() returned false, otherwise it will panic.
type Unsigned ¶
Unsigned is a constraint that permits any unsigned integer type. If future releases of Go add new predeclared unsigned integer types, this constraint will be modified to include them.
type Vector ¶
type Vector[T any] []T
Vector is a sequence container representing array that can change in size.
func MakeVectorCap ¶
MakeVectorCap creates an empty Vector object with specified capacity.
func MakeVectorOf ¶
MakeVectorOf creates an Vector object with initial values.
func (*Vector[T]) Append ¶
func (v *Vector[T]) Append(x ...T)
Append appends the values x... to the tail of the vector.
func (*Vector[T]) At ¶
At returns the element value at the index i. You can also use the [] operator, and it's better.
func (*Vector[T]) Clear ¶
func (v *Vector[T]) Clear()
Clear erases all elements from the vector. After this call, Len() returns zero. Leaves the Cap() of the vector unchanged.
func (*Vector[T]) Insert ¶
Insert inserts the values x... into the vector at index i. After the insertion, (*v)[i] == x[0]. Insert panics if i is out of range.
Complexity: O(len(s) + len(v)).
func (*Vector[T]) PushBack ¶
func (v *Vector[T]) PushBack(x T)
PushBack pushs an element to the end of the vector.
func (*Vector[T]) RemoveLength ¶
RemoveLength removes the elements in the range[i, i+len) from the vector.
func (*Vector[T]) RemoveRange ¶
RemoveRange removes the elements in the range[i, j) from the vector.
func (*Vector[T]) Reserve ¶
Reserve increases the capacity of the vector (the total number of elements that the vector can hold without requiring reallocation)to a value that's greater or equal to l. If l is greater than the current Cap(), new storage is allocated, otherwise the function does nothing.
Reserve() does not change the size of the vector.