File: countneg.c

package info (click to toggle)
nauty 2.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 100,416 kB
  • sloc: ansic: 125,567; sh: 4,157; makefile: 4,129
file content (153 lines) | stat: -rw-r--r-- 3,697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* countneg.c version 1.0; B D McKay, Dec 2022 */

#define USAGE "countneg [-ne] [infile]"

#define HELPTEXT \
"  Count graphs by number of vertices and/or number of edges\n\
\n\
     -n  Count by vertices\n\
     -e  Count by edges\n\
        Default and -ne are to count by both\n\
     -q  Suppress auxiliary output.\n\
  Use countg instead if incremental inputs are present.\n"

#include "gtools.h"

#define SPLAYNODE struct splay_t
struct splay_t
{
   SPLAYNODE *left,*right,*parent;
   long long n,e,count;
};

#define SCAN_ARGS
#define INSERT_ARGS , int n, size_t e
#define ACTION(p) { printf("%9lld ",(p)->count); \
                    if ((p)->n >= 0) printf(" n=%lld",(p)->n);\
                    if ((p)->e >= 0) printf(" e=%lld",(p)->e); \
                    printf("\n"); }
#define COMPARE(p) ((p)->n < n ? 1 : (p)->n > n ? -1 : e - (p)->e)
#define PRESENT(p) ++((p)->count)
#define NOT_PRESENT(p) { (p)->n = n; (p)->e = e; (p)->count = 1; }

static SPLAYNODE *root;
#include "splay.c"

int
main(int argc, char *argv[])
{
    int codetype;
    char *infilename,*line;
    FILE *infile;
    int argnum,j;
    char *arg,sw;
    boolean nswitch,eswitch,qswitch;
    boolean badargs;
    nauty_counter nin;
    int n,nprev;
    size_t e;
    long long lln,lle;
    double t0,t1;

    HELP; PUTVERSION;

    eswitch = nswitch = qswitch = FALSE;
    infilename = NULL;

    argnum = 0;
    badargs = FALSE;
    for (j = 1; !badargs && j < argc; ++j)
    {
        arg = argv[j];
        if (arg[0] == '-' && arg[1] != '\0')
        {
            ++arg;
            while (*arg != '\0')
            {
                sw = *arg++;
                     SWBOOLEAN('e',eswitch)
                else SWBOOLEAN('n',nswitch)
                else SWBOOLEAN('q',qswitch)
                else badargs = TRUE;
            }
        }
        else
        {
            ++argnum;
            if      (argnum == 1) infilename = arg;
            else                  badargs = TRUE;
        }
    }

    if (badargs || argnum > 1)
    {
        fprintf(stderr,">E Usage: %s\n",USAGE);
        GETHELP;
        exit(1);
    }

    if (!nswitch && !eswitch) nswitch = eswitch = TRUE;

    if (!qswitch)
    {
        fprintf(stderr,">A %s",argv[0]);
        if (nswitch && eswitch) fprintf(stderr," -ne");
        else if (eswitch) fprintf(stderr," -e");
        else if (nswitch) fprintf(stderr," -n");
        if (argnum > 0) fprintf(stderr," %s",infilename);
        fprintf(stderr,"\n");
        fflush(stderr);
    }

    if (infilename && infilename[0] == '-') infilename = NULL;
    infile = opengraphfile(infilename,&codetype,FALSE,1);
    if (!infile) exit(1);
    if (!infilename) infilename = "stdin";

    nin = 0;
    root = NULL;
    t0 = CPUTIME;
    nprev = 0;

    while ((line = gtools_getline(infile)) != NULL)
    {
        ++nin;
        if (line[0] == ';')
        {
            if (eswitch)
                gt_abort(
             ">E incremental sparse6 is not supported with -e; use countg\n");
            else
            {
                lln = nprev;
                lle = -1;
            }
        }
        else if (eswitch)
        {
            stringcounts(line,&n,&e);
            nprev = n;
            lln = (nswitch ? n : -1);
            lle = e;
        }
        else
        {
            nprev = graphsize(line);
            lln = nprev;
            lle = -1;
        }
        /* Note -ne is default, so "none" is impossible. */
 
        splay_insert(&root,lln,lle);
    }

    splay_scan(root);

    t1 = CPUTIME;

    if (!qswitch)
        fprintf(stderr,">Z " COUNTER_FMT " graphs altogether; %.2f sec\n",
                       nin,t1-t0);

    exit(0);
}