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