From 65357c8c46154de4e4eca14075bfe5523bb5fc14 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 7 Dec 2020 10:26:01 +0100 Subject: New upstream version 3.0.3 --- Vector.h | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'Vector.h') diff --git a/Vector.h b/Vector.h index 209e27c..ee51413 100644 --- a/Vector.h +++ b/Vector.h @@ -3,40 +3,38 @@ /* htop - Vector.h (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ #include "Object.h" -#define swap(a_,x_,y_) do{ void* tmp_ = a_[x_]; a_[x_] = a_[y_]; a_[y_] = tmp_; }while(0) +#include + #ifndef DEFAULT_SIZE -#define DEFAULT_SIZE -1 +#define DEFAULT_SIZE (-1) #endif typedef struct Vector_ { - Object **array; - ObjectClass* type; + Object** array; + const ObjectClass* type; int arraySize; int growthRate; int items; bool owner; } Vector; -Vector* Vector_new(ObjectClass* type, bool owner, int size); +Vector* Vector_new(const ObjectClass* type, bool owner, int size); void Vector_delete(Vector* this); -#ifdef DEBUG - -int Vector_count(Vector* this); - -#endif - void Vector_prune(Vector* this); -void Vector_quickSort(Vector* this); +void Vector_quickSortCustomCompare(Vector* this, Object_Compare compare); +static inline void Vector_quickSort(Vector* this) { + Vector_quickSortCustomCompare(this, this->type->compare); +} void Vector_insertionSort(Vector* this); @@ -52,29 +50,27 @@ void Vector_moveDown(Vector* this, int idx); void Vector_set(Vector* this, int idx, void* data_); -#ifdef DEBUG +#ifndef NDEBUG -Object* Vector_get(Vector* this, int idx); +Object* Vector_get(const Vector* this, int idx); +int Vector_size(const Vector* this); +unsigned int Vector_count(const Vector* this); -#else +#else /* NDEBUG */ -#define Vector_get(v_, idx_) ((v_)->array[idx_]) +static inline Object* Vector_get(Vector* this, int idx) { + return this->array[idx]; +} -#endif +static inline int Vector_size(const Vector* this) { + return this->items; +} -#ifdef DEBUG - -int Vector_size(Vector* this); - -#else - -#define Vector_size(v_) ((v_)->items) - -#endif +#endif /* NDEBUG */ void Vector_add(Vector* this, void* data_); -int Vector_indexOf(Vector* this, void* search_, Object_Compare compare); +int Vector_indexOf(const Vector* this, const void* search_, Object_Compare compare); void Vector_splice(Vector* this, Vector* from); -- cgit v1.2.3