| [2] | 1 | /* List implementation of a partition of consecutive integers.
|
|---|
| 2 | Copyright (C) 2000, 2001 Free Software Foundation, Inc.
|
|---|
| 3 | Contributed by CodeSourcery, LLC.
|
|---|
| 4 |
|
|---|
| 5 | This file is part of GNU CC.
|
|---|
| 6 |
|
|---|
| 7 | GNU CC is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 10 | any later version.
|
|---|
| 11 |
|
|---|
| 12 | GNU CC is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | GNU General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with GNU CC; see the file COPYING. If not, write to
|
|---|
| 19 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 20 | Boston, MA 02111-1307, USA. */
|
|---|
| 21 |
|
|---|
| 22 | #ifdef HAVE_CONFIG_H
|
|---|
| 23 | #include "config.h"
|
|---|
| 24 | #endif
|
|---|
| 25 |
|
|---|
| 26 | #ifdef HAVE_STDLIB_H
|
|---|
| 27 | #include <stdlib.h>
|
|---|
| 28 | #endif
|
|---|
| 29 |
|
|---|
| 30 | #ifdef HAVE_STRING_H
|
|---|
| 31 | #include <string.h>
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | #include "libiberty.h"
|
|---|
| 35 | #include "partition.h"
|
|---|
| 36 |
|
|---|
| 37 | static int elem_compare PARAMS ((const void *, const void *));
|
|---|
| 38 |
|
|---|
| 39 | /* Creates a partition of NUM_ELEMENTS elements. Initially each
|
|---|
| 40 | element is in a class by itself. */
|
|---|
| 41 |
|
|---|
| 42 | partition
|
|---|
| 43 | partition_new (num_elements)
|
|---|
| 44 | int num_elements;
|
|---|
| 45 | {
|
|---|
| 46 | int e;
|
|---|
| 47 |
|
|---|
| 48 | partition part = (partition)
|
|---|
| 49 | xmalloc (sizeof (struct partition_def) +
|
|---|
| 50 | (num_elements - 1) * sizeof (struct partition_elem));
|
|---|
| 51 | part->num_elements = num_elements;
|
|---|
| 52 | for (e = 0; e < num_elements; ++e)
|
|---|
| 53 | {
|
|---|
| 54 | part->elements[e].class_element = e;
|
|---|
| 55 | part->elements[e].next = &(part->elements[e]);
|
|---|
| 56 | part->elements[e].class_count = 1;
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | return part;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | /* Freeds a partition. */
|
|---|
| 63 |
|
|---|
| 64 | void
|
|---|
| 65 | partition_delete (part)
|
|---|
| 66 | partition part;
|
|---|
| 67 | {
|
|---|
| 68 | free (part);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | /* Unites the classes containing ELEM1 and ELEM2 into a single class
|
|---|
| |
|---|