From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id D33FE385AC24 for ; Tue, 5 Oct 2021 14:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D33FE385AC24 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy03.your-server.de ([88.198.220.132]) by dedi548.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1mXlF7-000B4M-Ti; Tue, 05 Oct 2021 16:16:30 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mXlF7-000T9F-Qm; Tue, 05 Oct 2021 16:16:29 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 8640748007C; Tue, 5 Oct 2021 16:16:29 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 9SEh8xcnZEW4; Tue, 5 Oct 2021 16:16:29 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 2CF974800EA; Tue, 5 Oct 2021 16:16:29 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id L2z6py5dL3wP; Tue, 5 Oct 2021 16:16:29 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 0617348007E; Tue, 5 Oct 2021 16:16:29 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Cc: devel@rtems.org Subject: [PATCH 3/4] sys/tree.h: Add parent rotations Date: Tue, 5 Oct 2021 16:16:24 +0200 Message-Id: <20211005141625.31585-4-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211005141625.31585-1-sebastian.huber@embedded-brains.de> References: <20211005141625.31585-1-sebastian.huber@embedded-brains.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.3/26313/Tue Oct 5 11:04:18 2021) X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Oct 2021 14:16:35 -0000 Add specialized rotations RB_PARENT_ROTATE_LEFT() and RB_PARENT_ROTATE_RI= GHT() which may be used if the parent node exists and the direction of the chil= d is known. The specialized rotations are derived from RB_ROTATE_LEFT() and RB_ROTATE_RIGHT() where the RB_SWAP_CHILD() was replaced by a simple assignment. --- newlib/libc/include/sys/tree.h | 36 ++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/newlib/libc/include/sys/tree.h b/newlib/libc/include/sys/tre= e.h index 180809e9b..5fc052817 100644 --- a/newlib/libc/include/sys/tree.h +++ b/newlib/libc/include/sys/tree.h @@ -381,6 +381,30 @@ struct { \ RB_AUGMENT(elm); \ } while (/*CONSTCOND*/ 0) =20 +#define RB_PARENT_ROTATE_LEFT(parent, left, tmp, field) do { \ + (tmp) =3D RB_RIGHT(left, field); \ + if ((RB_RIGHT(left, field) =3D RB_LEFT(tmp, field)) !=3D NULL) { \ + RB_SET_PARENT(RB_RIGHT(left, field), left, field); \ + } \ + RB_SET_PARENT(tmp, parent, field); \ + RB_LEFT(parent, field) =3D (tmp); \ + RB_LEFT(tmp, field) =3D (left); \ + RB_SET_PARENT(left, tmp, field); \ + RB_AUGMENT(left); \ +} while (/*CONSTCOND*/ 0) + +#define RB_PARENT_ROTATE_RIGHT(parent, elm, tmp, field) do { \ + (tmp) =3D RB_LEFT(elm, field); \ + if ((RB_LEFT(elm, field) =3D RB_RIGHT(tmp, field)) !=3D NULL) { \ + RB_SET_PARENT(RB_LEFT(elm, field), elm, field); \ + } \ + RB_SET_PARENT(tmp, parent, field); \ + RB_RIGHT(parent, field) =3D (tmp); \ + RB_RIGHT(tmp, field) =3D (elm); \ + RB_SET_PARENT(elm, tmp, field); \ + RB_AUGMENT(elm); \ +} while (/*CONSTCOND*/ 0) + /* Generates prototypes and inline functions */ #define RB_PROTOTYPE(name, type, field, cmp) \ RB_PROTOTYPE_INTERNAL(name, type, field, cmp,) @@ -454,7 +478,8 @@ name##_RB_INSERT_COLOR(struct name *head, struct type= *elm) \ continue; \ } \ if (RB_RIGHT(parent, field) =3D=3D elm) { \ - RB_ROTATE_LEFT(head, parent, tmp, field);\ + RB_PARENT_ROTATE_LEFT(gparent, parent, \ + tmp, field); \ tmp =3D parent; \ parent =3D elm; \ elm =3D tmp; \ @@ -470,7 +495,8 @@ name##_RB_INSERT_COLOR(struct name *head, struct type= *elm) \ continue; \ } \ if (RB_LEFT(parent, field) =3D=3D elm) { \ - RB_ROTATE_RIGHT(head, parent, tmp, field);\ + RB_PARENT_ROTATE_RIGHT(gparent, parent, \ + tmp, field); \ tmp =3D parent; \ parent =3D elm; \ elm =3D tmp; \ @@ -500,7 +526,8 @@ name##_RB_REMOVE_COLOR(struct name *head, struct type= *parent) \ RB_COLOR(RB_RIGHT(tmp, field), field) =3D RB_BLACK; \ else if (RB_ISRED(RB_LEFT(tmp, field), field)) { \ struct type *oleft; \ - RB_ROTATE_RIGHT(head, tmp, oleft, field); \ + RB_PARENT_ROTATE_RIGHT(parent, tmp, \ + oleft, field); \ RB_COLOR(oleft, field) =3D RB_BLACK; \ tmp =3D oleft; \ } else { \ @@ -525,7 +552,8 @@ name##_RB_REMOVE_COLOR(struct name *head, struct type= *parent) \ RB_COLOR(RB_LEFT(tmp, field), field) =3D RB_BLACK; \ else if (RB_ISRED(RB_RIGHT(tmp, field), field)) { \ struct type *oright; \ - RB_ROTATE_LEFT(head, tmp, oright, field); \ + RB_PARENT_ROTATE_LEFT(parent, tmp, \ + oright, field); \ RB_COLOR(oright, field) =3D RB_BLACK; \ tmp =3D oright; \ } else { \ --=20 2.26.2