Example #1
0
Bnode *Btree_delete(int key, Bnode *base, int *num)
{
    Bnode *t, *parent;
    int pi = 0;
    int ti;
    parent = base;
    t = base->ptr[0];
    while (t != NULL)
    {
        if (t->n <= M && parent != base)
            if (!borrow_key(parent, pi)) t = bind_node(parent, pi, base);
        if ((ti = in_Bnode(key, t)) >= 0)
        {
            if (t->ptr[0] == NULL) break;  /* if external break */
            else make_swap(parent, t, &key, ti);
        }
        parent = t;
        for (pi = 0; pi < t->n && key >= t->key[pi]; pi++);
        t = t->ptr[pi];
    }
    if (t == NULL) return NULL;  /* can't find */
    if (t->n <= M && parent != base)  /* external but less M */
        if (!borrow_key(parent, pi)) t = bind_node(parent, pi, base);
    delete_key(t, in_Bnode(key, t));
    (*num)--;
    return t;
}
Example #2
0
static	void	d_compact2(void)
{
	register int	 b, i;
	VMHEAD	HUGE	*v;
	int	handle;
	char	fn[sizeof DMfile];
#ifdef NO_ALLOCA
	char	dbuf[NO_ALLOCA];
	unsigned	bufsiz = NO_ALLOCA;
#else
	char	*dbuf;
	unsigned	bufsiz = 2048;
#endif
	FNAME(d_compact2);

#ifndef NO_ALLOCA
	while (NULL == (dbuf = alloca(bufsiz)))
		bufsiz /= 2;
#endif
	strcpy(fn, DMfile);
	handle = DMhandle;
	dm_new();
	if (make_swap())
		error(fun, "make_swap");
	for (b=0 ; b !=	VMBASESIZ  &&  (v=VMbase[b]) ; ++b)
		for (i=b?0:1 ; i != VMLEGSIZ  ;	++i)
			if ((v[i].type & (MT_MEMORY | MT_DISK))	 &&  v[i].diskadd != -1L)
				if (v[i].type &	MT_MEMORY)  {
					v[i].type |= MT_DIRTY;
					v[i].diskadd = -1L;
				}  else	 {
					unsigned int n = bufsiz	< v[i].size ? bufsiz : v[i].size;
					MAX_SIZ_TYP	m = v[i].size;

					if (-1L	== lseek(handle, v[i].diskadd, SEEK_SET))
						error(fun, "lseek");
					while (m)  {
						n = n >	m ? m :	n;
						if (n != read(handle, dbuf, n))
							error(fun, "read");
						if (n != write(DMhandle, dbuf, n))
							error(fun, "write");
						m -= n;
					}
					v[i].diskadd = DMnext;
					DMnext += v[i].size;
				}
	if (-1 == close(handle))
		error(fun, "close");
	if (-1 == unlink(fn))
		error(fun, "unlink");
}
Example #3
0
int	VM_init(void)
{
	int	r;
	static	int	once = 1;

	if (DMhandle !=	-1)
		return(0);
	if (once)  {
		once = 0;
#ifndef	NO_ATEXIT
		atexit(VM_fcore);
#endif
	}
	dm_new();
	VMlive	 = 0;
	VMdisk	 = 0;
	VMnfreez = 0;
	VMnifrez = 0;
	DMncomp	 = 0;
	if (r=make_swap())
		return(r);
	return(0);
}