1*38fd1498Szrj /* List implementation of a partition of consecutive integers. 2*38fd1498Szrj Copyright (C) 2000-2018 Free Software Foundation, Inc. 3*38fd1498Szrj Contributed by CodeSourcery, LLC. 4*38fd1498Szrj 5*38fd1498Szrj This file is part of GCC. 6*38fd1498Szrj 7*38fd1498Szrj GCC is free software; you can redistribute it and/or modify 8*38fd1498Szrj it under the terms of the GNU General Public License as published by 9*38fd1498Szrj the Free Software Foundation; either version 2, or (at your option) 10*38fd1498Szrj any later version. 11*38fd1498Szrj 12*38fd1498Szrj GCC is distributed in the hope that it will be useful, 13*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of 14*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*38fd1498Szrj GNU General Public License for more details. 16*38fd1498Szrj 17*38fd1498Szrj You should have received a copy of the GNU General Public License 18*38fd1498Szrj along with GCC; see the file COPYING. If not, write to 19*38fd1498Szrj the Free Software Foundation, 51 Franklin Street - Fifth Floor, 20*38fd1498Szrj Boston, MA 02110-1301, USA. */ 21*38fd1498Szrj 22*38fd1498Szrj /* This package implements a partition of consecutive integers. The 23*38fd1498Szrj elements are partitioned into classes. Each class is represented 24*38fd1498Szrj by one of its elements, the canonical element, which is chosen 25*38fd1498Szrj arbitrarily from elements in the class. The principal operations 26*38fd1498Szrj on a partition are FIND, which takes an element, determines its 27*38fd1498Szrj class, and returns the canonical element for that class, and UNION, 28*38fd1498Szrj which unites the two classes that contain two given elements into a 29*38fd1498Szrj single class. 30*38fd1498Szrj 31*38fd1498Szrj The list implementation used here provides constant-time finds. By 32*38fd1498Szrj storing the size of each class with the class's canonical element, 33*38fd1498Szrj it is able to perform unions over all the classes in the partition 34*38fd1498Szrj in O (N log N) time. */ 35*38fd1498Szrj 36*38fd1498Szrj #ifndef _PARTITION_H 37*38fd1498Szrj #define _PARTITION_H 38*38fd1498Szrj 39*38fd1498Szrj #ifdef __cplusplus 40*38fd1498Szrj extern "C" { 41*38fd1498Szrj #endif /* __cplusplus */ 42*38fd1498Szrj 43*38fd1498Szrj #include "ansidecl.h" 44*38fd1498Szrj #include <stdio.h> 45*38fd1498Szrj 46*38fd1498Szrj struct partition_elem 47*38fd1498Szrj { 48*38fd1498Szrj /* The next element in this class. Elements in each class form a 49*38fd1498Szrj circular list. */ 50*38fd1498Szrj struct partition_elem* next; 51*38fd1498Szrj /* The canonical element that represents the class containing this 52*38fd1498Szrj element. */ 53*38fd1498Szrj int class_element; 54*38fd1498Szrj /* The number of elements in this class. Valid only if this is the 55*38fd1498Szrj canonical element for its class. */ 56*38fd1498Szrj unsigned class_count; 57*38fd1498Szrj }; 58*38fd1498Szrj 59*38fd1498Szrj typedef struct partition_def 60*38fd1498Szrj { 61*38fd1498Szrj /* The number of elements in this partition. */ 62*38fd1498Szrj int num_elements; 63*38fd1498Szrj /* The elements in the partition. */ 64*38fd1498Szrj struct partition_elem elements[1]; 65*38fd1498Szrj } *partition; 66*38fd1498Szrj 67*38fd1498Szrj extern partition partition_new (int); 68*38fd1498Szrj extern void partition_delete (partition); 69*38fd1498Szrj extern int partition_union (partition, int, int); 70*38fd1498Szrj extern void partition_print (partition, FILE*); 71*38fd1498Szrj 72*38fd1498Szrj /* Returns the canonical element corresponding to the class containing 73*38fd1498Szrj ELEMENT__ in PARTITION__. */ 74*38fd1498Szrj 75*38fd1498Szrj #define partition_find(partition__, element__) \ 76*38fd1498Szrj ((partition__)->elements[(element__)].class_element) 77*38fd1498Szrj 78*38fd1498Szrj #ifdef __cplusplus 79*38fd1498Szrj } 80*38fd1498Szrj #endif /* __cplusplus */ 81*38fd1498Szrj 82*38fd1498Szrj #endif /* _PARTITION_H */ 83