Next: , Previous: , Up: Bitmapped B-tree Fixed Size Data Arrays   [Index]


3.2.2.2 The Data Move Method

The method moves data from some location to another. Its signature is:

int (*)(void *, void *, unsigned);

The first argument is the target location, the second the source location, the third the item count to be moved.

13 byte string data items example:

static int
move(void *target, void *source, unsigned count)
{
    memmove(target, source, count * 13);

    return 0;
}

Unsigned long data items example:

static int
move(void *target, void *source, unsigned count)
{
    memmove(target, source, count * sizeof(unsigned long));

    return 0;
}

Same unsigned long data items example, no memmove:

static int
move(void *target, void *source, unsigned count)
{
    unsigned long *s, *t;

    s = source;
    t = target;
    if (count ^ 1) {
	if (t < s) {
	    for (; count; count--) {
		*t++ = *s++;
	    }
	} else {
	    s += count;
	    if (t < s) {
		t += count;
		for (; count; count--) {
		    *--t = *--s;
		}
	    } else {
		s -= count;
		for (; count; count--) {
		    *t++ = *s++;
		}
	    }
	}
    } else {
	*t++ = *s++;
    }

    return 0;
}