/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
parcel Lucy;
__C__
#include "Lucy/Util/SortUtils.h"
typedef chy_bool_t
(*lucy_VA_gather_test_t)(lucy_VArray *self, uint32_t tick, void *data);
#ifdef LUCY_USE_SHORT_NAMES
#define lucy_VA_gather_test_t lucy_VA_gather_test_t
#endif
__END_C__
/** Variable-sized array.
*/
class Lucy::Object::VArray cnick VA inherits Lucy::Object::Obj {
Obj **elems;
uint32_t size;
uint32_t cap;
inert incremented VArray*
new(uint32_t capacity);
/**
* @param capacity Initial number of elements that the object will be able
* to hold before reallocation.
*/
inert VArray*
init(VArray *self, uint32_t capacity);
/** Push an item onto the end of a VArray.
*/
void
Push(VArray *self, decremented Obj *element);
/** Push all the elements of another VArray onto the end of this one.
*/
void
Push_VArray(VArray *self, VArray *other);
/** Pop an item off of the end of a VArray.
*/
incremented nullable Obj*
Pop(VArray *self);
/** Unshift an item onto the front of a VArray.
*/
void
Unshift(VArray *self, decremented Obj *element);
/** Shift an item off of the front of a VArray.
*/
incremented nullable Obj*
Shift(VArray *self);
/** Ensure that the VArray has room for at least capacity
* elements.
*/
void
Grow(VArray *self, uint32_t capacity);
/** Fetch the element at tick.
*/
nullable Obj*
Fetch(VArray *self, uint32_t tick);
/** Store an element at index tick
, possibly displacing an
* existing element.
*/
void
Store(VArray *self, uint32_t tick, decremented Obj *elem);
/** Replace an element in the VArray with NULL and return it.
*
* @return whatever was stored at tick
.
*/
incremented nullable Obj*
Delete(VArray *self, uint32_t tick);
/** Remove length
elements from the array, starting at
* offset
. Move elements over to fill in the gap.
*/
void
Excise(VArray *self, uint32_t offset, uint32_t length);
/** Clone the VArray but merely increment the refcounts of its elements
* rather than clone them.
*/
incremented VArray*
Shallow_Copy(VArray *self);
/** Dupe the VArray, cloning each internal element.
*/
public incremented VArray*
Clone(VArray *self);
/** Quicksort the VArry using the supplied comparison routine. Safety
* checks are the responsibility of the caller.
*
* @param compare Comparison routine. The default uses Obj_Compare_To and
* sorts NULL elements towards the end.
* @param context Argument supplied to the comparison routine.
*/
void
Sort(VArray *self, lucy_Sort_compare_t compare = NULL,
void *context = NULL);
/** Set the size for the VArray. If the new size is larger than the
* current size, grow the object to accommodate NULL elements; if smaller
* than the current size, decrement and discard truncated elements.
*/
void
Resize(VArray *self, uint32_t size);
/** Empty the VArray.
*/
void
Clear(VArray *self);
/** Accessor for size
member.
*/
public uint32_t
Get_Size(VArray *self);
/** Accessor for capacity
member.
*/
uint32_t
Get_Capacity(VArray *self);
/** Return all elements for which test
returns true.
*/
public incremented VArray*
Gather(VArray *self, lucy_VA_gather_test_t test, void *data);
public bool_t
Equals(VArray *self, Obj *other);
public incremented VArray*
Dump(VArray *self);
public incremented VArray*
Load(VArray *self, Obj *dump);
public void
Serialize(VArray *self, OutStream *outstream);
public incremented VArray*
Deserialize(VArray *self, InStream *instream);
public void
Destroy(VArray *self);
}