1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-05 07:45:50 +01:00

- added WMRemoveFromArrayMatching(array, match, cdata), which will remove the

first element in the array that is matched by match(item, cdata)==True.
- added WMArrayFirst(), WMArrayLast(), WMArrayNext() and WMArrayPrevious()
  functions and also WM_ITERATE_ARRAY() and WM_ETARETI_ARRAY() macros, to make
  interfaces to WMBag and WMArray similar and to make life a little simpler
  when iterating through all elements of an array.
- replaced bags with arrays wherever appropriate. This will improve
  performance a bit.
- replaced some recursive code with iterative code in WINGs/selection.c
- some code cleanup is src/
This commit is contained in:
dan
2001-04-15 01:22:56 +00:00
parent a41b8993e5
commit 046403dbbb
27 changed files with 581 additions and 662 deletions

View File

@@ -193,14 +193,23 @@ WMDeleteFromArray(WMArray *array, int index)
int
WMRemoveFromArray(WMArray *array, void *item)
WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata)
{
int i;
for (i = 0; i < array->itemCount; i++) {
if (array->items[i] == item) {
WMDeleteFromArray(array, i);
return 1;
if (match != NULL) {
for (i = 0; i < array->itemCount; i++) {
if ((*match)(array->items[i], cdata)) {
WMDeleteFromArray(array, i);
return 1;
}
}
} else {
for (i = 0; i < array->itemCount; i++) {
if (array->items[i] == cdata) {
WMDeleteFromArray(array, i);
return 1;
}
}
}
@@ -304,3 +313,54 @@ WMGetSubarrayWithRange(WMArray* array, WMRange aRange)
}
void*
WMArrayFirst(WMArray *array, WMArrayIterator *iter)
{
if (array->itemCount == 0) {
*iter = WANotFound;
return NULL;
} else {
*iter = 0;
return array->items[0];
}
}
void*
WMArrayLast(WMArray *array, WMArrayIterator *iter)
{
if (array->itemCount == 0) {
*iter = WANotFound;
return NULL;
} else {
*iter = array->itemCount-1;
return array->items[*iter];
}
}
void*
WMArrayNext(WMArray *array, WMArrayIterator *iter)
{
if (*iter >= 0 && *iter < array->itemCount-1) {
return array->items[++(*iter)];
} else {
*iter = WANotFound;
return NULL;
}
}
void*
WMArrayPrevious(WMArray *array, WMArrayIterator *iter)
{
if (*iter > 0 && *iter < array->itemCount) {
return array->items[--(*iter)];
} else {
*iter = WANotFound;
return NULL;
}
}