static int compactifyStrings(Page pg, int m) 
    {
        int i, j, offs, len, n = getnItems(pg);
        int[] size  = new int[keySpace/2+1];
        int[] index = new int[keySpace/2+1];
        if (m == 0) { 
            return n;
        }
        int nZeroLengthStrings = 0;
        if (m < 0) {
            m = -m;
            for (i = 0; i < n-m; i++) { 
                len = getKeyStrSize(pg, i);
                if (len != 0) { 
                    offs = getKeyStrOffs(pg, i) >>> 1;
                    size[offs + len] = len;
                    index[offs + len] = i;
                } else { 
                    nZeroLengthStrings += 1;
                }
            }   
            for (; i < n; i++) { 
                len = getKeyStrSize(pg, i);
                if (len != 0) { 
                    offs = getKeyStrOffs(pg, i) >>> 1;
                    size[offs + len] = len;
                    index[offs + len] = -1;
                }
            }
        } else { 
            for (i = 0; i < m; i++) { 
                len = getKeyStrSize(pg, i);
                if (len != 0) { 
                    offs = getKeyStrOffs(pg, i) >>> 1;
                    size[offs + len] = len;
                    index[offs + len] = -1;
                }
            }
            for (; i < n; i++) { 
                len = getKeyStrSize(pg, i);
                if (len != 0) { 
                    offs = getKeyStrOffs(pg, i) >>> 1;
                    size[offs + len] = len;
                    index[offs + len] = i - m;
                } else { 
                    nZeroLengthStrings += 1;
                }                   
                setKeyStrOid(pg, i-m, getKeyStrOid(pg, i));
                setKeyStrSize(pg, i-m, len);
            }   
            setKeyStrOid(pg, i-m, getKeyStrOid(pg, i));
        }
        int nItems = n -= m;
        n -= nZeroLengthStrings;
        for (offs = keySpace/2, i = offs; n != 0; i -= len) { 
            len = size[i];
            j = index[i];
            if (j >= 0) {
                offs -= len;
                n -= 1;
                setKeyStrOffs(pg, j, offs*2);
                if (offs != i - len) { 
                    memcpy(pg, offs, pg, i - len, len, 2);
                }
            }
        }
        return nItems;
    }