MCPcopy Create free account
hub / github.com/GJDuck/e9patch / malloc_rebalance_remove

Function malloc_rebalance_remove

examples/stdlib.c:1945–2034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1943}
1944
1945static void malloc_rebalance_remove(struct malloc_pool_s *pool,
1946 uint32_t parent, uint32_t n)
1947{
1948 uint32_t tmp;
1949 while ((n == MA_NIL || MA_COLOR(pool, n) == MA_BLACK) && n != pool->root)
1950 {
1951 if (MA_LEFT(pool, parent) == n)
1952 {
1953 tmp = MA_RIGHT(pool, parent);
1954 if (MA_COLOR(pool, tmp) == MA_RED)
1955 {
1956 MA_COLOR(pool, tmp) = MA_BLACK;
1957 MA_COLOR(pool, parent) = MA_RED;
1958 malloc_rotate_left(pool, parent);
1959 tmp = MA_RIGHT(pool, parent);
1960 }
1961 if ((MA_LEFT(pool, tmp) == MA_NIL ||
1962 MA_COLOR(pool, MA_LEFT(pool, tmp)) == MA_BLACK) &&
1963 (MA_RIGHT(pool, tmp) == MA_NIL ||
1964 MA_COLOR(pool, MA_RIGHT(pool, tmp)) == MA_BLACK))
1965 {
1966 MA_COLOR(pool, tmp) = MA_RED;
1967 n = parent;
1968 parent = MA_PARENT(pool, n);
1969 }
1970 else
1971 {
1972 if (MA_RIGHT(pool, tmp) == MA_NIL ||
1973 MA_COLOR(pool, MA_RIGHT(pool, tmp)) == MA_BLACK)
1974 {
1975 uint32_t oleft;
1976 if ((oleft = MA_LEFT(pool, tmp)) != MA_NIL)
1977 MA_COLOR(pool, oleft) = MA_BLACK;
1978 MA_COLOR(pool, tmp) = MA_RED;
1979 malloc_rotate_right(pool, tmp);
1980 tmp = MA_RIGHT(pool, parent);
1981 }
1982 MA_COLOR(pool, tmp) = MA_COLOR(pool, parent);
1983 MA_COLOR(pool, parent) = MA_BLACK;
1984 if (MA_RIGHT(pool, tmp))
1985 MA_COLOR(pool, MA_RIGHT(pool, tmp)) = MA_BLACK;
1986 malloc_rotate_left(pool, parent);
1987 n = pool->root;
1988 break;
1989 }
1990 }
1991 else
1992 {
1993 tmp = MA_LEFT(pool, parent);
1994 if (MA_COLOR(pool, tmp) == MA_RED)
1995 {
1996 MA_COLOR(pool, tmp) = MA_BLACK;
1997 MA_COLOR(pool, parent) = MA_RED;
1998 malloc_rotate_right(pool, parent);
1999 tmp = MA_LEFT(pool, parent);
2000 }
2001 if ((MA_LEFT(pool, tmp) == MA_NIL ||
2002 MA_COLOR(pool, MA_LEFT(pool, tmp)) == MA_BLACK) &&

Callers 1

malloc_removeFunction · 0.85

Calls 2

malloc_rotate_leftFunction · 0.85
malloc_rotate_rightFunction · 0.85

Tested by

no test coverage detected