the_Foundation 1.0
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Functions
sortedarray.h File Reference
#include "array.h"

Data Structures

struct  iSortedArray
 

Macros

#define at_SortedArray(d, pos)   at_Array(&(d)->values, pos)
 
#define isEmpty_SortedArray(d)   isEmpty_Array(&(d)->values)
 

Typedefs

typedef int(* iSortedArrayCompareElemFunc) (const void *, const void *)
 

Functions

iSortedArray * new_SortedArray (size_t elementSize, iSortedArrayCompareElemFunc cmp)
 
void delete_SortedArray (iSortedArray *)
 
void init_SortedArray (iSortedArray *, size_t elementSize, iSortedArrayCompareElemFunc cmp)
 
void deinit_SortedArray (iSortedArray *)
 
iSortedArray * copy_SortedArray (const iSortedArray *)
 
iBool contains_SortedArray (const iSortedArray *, const void *value)
 
iBool locate_SortedArray (const iSortedArray *, const void *value, size_t *pos_out)
 
iRanges locateRange_SortedArray (const iSortedArray *, const void *value, iSortedArrayCompareElemFunc relaxed)
 
void clear_SortedArray (iSortedArray *)
 
iBool insert_SortedArray (iSortedArray *, const void *value)
 
iBool remove_SortedArray (iSortedArray *, const void *value)
 
iBool insertIf_SortedArray (iSortedArray *, const void *value, iSortedArrayCompareElemFunc pred)
 

Detailed Description

SortedArray of sorted unique values.

Elements of an Array are stored sequentially in a single block of memory. When elements are inserted, the data is copied into the Array.

SortedArray is an Array whose elements are sorted according to a comparison function. It is best suited when there is a relatively small amount of insertions/removals but lots of searches.

Complexity
Authors
Copyright (c) 2017 Jaakko Keränen jaakk.nosp@m.o.ke.nosp@m.ranen.nosp@m.@iki.nosp@m..fi
License

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ insertIf_SortedArray()

iBool insertIf_SortedArray ( iSortedArray *  ,
const void *  value,
iSortedArrayCompareElemFunc  pred 
)

Inserts a new element, or replaces an existing one if the provided predicate is true.

Parameters
valueValue to be inserted.
predPredicate callback that returns non-zero if the value should be inserted. Called to compare an existing value and the new value. Called as: pred(new, old)
Returns
True if value was inserted to the array.

◆ locateRange_SortedArray()

iRanges locateRange_SortedArray ( const iSortedArray *  ,
const void *  value,
iSortedArrayCompareElemFunc  relaxed 
)

Locates a range of elements in the array.

Parameters
valueValue to be used for comparisons.
relaxedOptional comparison function that is more relaxed than the array's own element comparison function. This allows locating a range of elements that match partially. The relaxed comparison must be compatible with the array's comparison function. Set to NULL to use the array's comparison function.
Returns
Located range of elements. This is an empty range if nothing was found to match.