Browse Source

Update: Major changes to all files to use elfc_lib. Many small improvements and fixes.

Sebastian Kreisel 1 year ago
parent
commit
faf49ba4dd

+ 2 - 1
.gitignore

@@ -1,10 +1,11 @@
 /saves
 /prof
 /_old
+/old
 /bin
 .stack-work
 *.prof
 *.out*
 .#*
 prof.txt
-vgcore*
+vgcore*

+ 9 - 11
Makefile

@@ -1,5 +1,5 @@
 CC = gcc
-CC_FLAGS = -Wall -O3
+CC_FLAGS = -Wall -O3 -std=c99 -I../elfclib/include
 LN_FLAGS = -lm -L../elfclib/bin -lelfc
 
 # ----------------------------------------------------------------------------
@@ -30,15 +30,13 @@ BIN = ./bin/asoc
 TEST = ./bin/testasoc
 
 all: $(BIN)
-prf: $(BIN)
-opt: $(BIN)
 test: $(TEST)
 
 $(BIN): $(OBJ_FILES)
-	$(CC) $(LN_FLAGS) $^ -o $@
+	$(CC) $^ $(LN_FLAGS) -o $@
 
 $(TEST): $(OBJ_FILES)
-	$(CC) $(LN_FLAGS) $^ -o $@
+	$(CC) $^ $(LN_FLAGS) -o $@
 
 -include $(DEP_FILES)
 
@@ -50,17 +48,17 @@ bin/%.o: test/%.c
 bin/%.o: src/%.c
 	$(CC) $(CC_FLAGS) $(INCLUDES) -MMD -c $< -o $@
 
-bin/%.o: src/gen/%.c
-	$(CC) $(CC_FLAGS) $(INCLUDES) -MMD -c $< -o $@
+#bin/%.o: src/gen/%.c
+#	$(CC) $(CC_FLAGS) $(INCLUDES) -MMD -c $< -o $@
 
-bin/%.o: src/common/%.c
-	$(CC) $(CC_FLAGS) $(INCLUDES) -MMD -c $< -o $@
+#bin/%.o: src/common/%.c
+#	$(CC) $(CC_FLAGS) $(INCLUDES) -MMD -c $< -o $@
 
 bin/%.o: src/group/%.c
 	$(CC) $(CC_FLAGS) $(INCLUDES) -MMD -c $< -o $@
 
-bin/%.o: src/ring/%.c
-	$(CC) $(CC_FLAGS) $(INCLUDES) -MMD -c $< -o $@
+#bin/%.o: src/ring/%.c
+#	$(CC) $(CC_FLAGS) $(INCLUDES) -MMD -c $< -o $@
 
 clean:
 	-rm ./bin/*

+ 0 - 13
README.md

@@ -1,13 +0,0 @@
-# Asocgen
-I want to re-discover groups of finite order. For that I need to find
-associative structures. So here I am searching for them in *not haskell* (well
-turns out C is better for this job).
-
-# Questions
-* Are there configurations of incomplete tables which are incomplete
-  associative but will never lead to a complete associative table?
-* Schemes where we try to keep to number of allowed symbols to a minimum, ie.
-  not just increasing with UP but picking from a minimal list of symbols to
-  help associativity detection.
-
-# Main Program

+ 16 - 0
README.txt

@@ -0,0 +1,16 @@
+Playing around with finite groups of low order (< 0xffff). Groups are
+treated as black box object, i.e. are given by a multiplication table.
+
+
+Main features (will) include:
+* Generating the "base"-groups: Cn, Sn, GL over finite fields, ...
+* Basic property and subgroup analysis
+* Computing minimal generating sets
+* Checking for isomorphism
+* Storing groups as multiplication table (plus additional information)
+  to files
+
+
+Groups can be generated as subgroups of base groups such as Sn and GL over
+finite fields. Groups may also be constructed with methods such as direct
+products, commutators, ...

+ 0 - 2
TODO.org

@@ -1,5 +1,3 @@
-#+STARTUP: showall
-
 * Urgent
 ** TODO group_gen: Make independent of neutral == 0 and improve return value
 ** TODO ring: Function to construct Z/pZ

+ 0 - 100
src/common/common.c

@@ -1,100 +0,0 @@
-#include <string.h>
-#include <math.h>
-
-#include "common.h"
-#include "sarray16.h"
-#include "sbitfield.h"
-#include "smap.h"
-
-void padString(char *string, uint32_t pad) {
-  uint32_t i;
-  for(i = 0; i < pad; i++) {
-    sprintf(string + strlen(string), " ");
-  }
-}
-
-void padStringForInt(char *string, uint32_t val, uint32_t numDigits) {
-  double valLen;
-  if(val > 0) {
-    valLen = log10(val);
-  } else {
-    valLen = 0;
-  }
-  uint32_t toPad = numDigits - floor(valLen) - 1;
-  padString(string, toPad);
-}
-
-void sprint_uint(char *string, uint32_t val) {
-  if(val == 0xff) {
-    padStringForInt(string, 0, 3);
-    sprintf(string + strlen(string), "~ ");
-  } else {
-    padStringForInt(string, val, 3);
-    sprintf(string + strlen(string), "%u ", val);
-  }
-}
-
-void printError(char *error) {
-  fprintf(stderr, "%s", error);
-}
-
-void sprintBinary_uint8(char *pstring, uint8_t n) {
-  uint32_t i;
-  for(i = 0; i < 16; i++) {
-    if((n & (1 << (15 - i))) == 0) {
-      pstring[i] = '0';
-    } else {
-      pstring[i] = '1';
-    }
-  }
-}
-
-// --------------------------------------------------------------------------
-
-uint32_t factorial(uint32_t n) {
-#ifdef BOUNDS_CHECK
-  if(n > 12) {
-    printError("error: factorial only fits into uint32 for n <= 12");
-    exit(1);
-  }
-#endif
-  if(n == 0) {
-    return 1;
-  } else {
-    return n * factorial(n - 1);
-  }
-}
-
-Array_uint16 *getPrimeFactors_alloc(uint16_t n) {
-  Array_uint16 *factors = aui16_alloc(n / 2); // *might* be improved
-  uint32_t i;
-  uint32_t c = 0;
-  uint32_t sqrtn = floor(sqrt(n));
-  for(i = 2; i <= sqrtn; i++) {
-    while(n % i == 0) {
-      *aui16_at(factors, c) = i;
-      c++;
-      n = n / i;
-    }
-  }
-  if(n > 2) {
-    *aui16_at(factors, c) = n;
-    c++;
-  }
-  aui16_shrink(factors, c);
-  return factors;
-}
-
-Array_uint16 *getFactors_alloc(uint16_t n) {
-  Array_uint16 *factors = aui16_alloc(n / 2 + 1); // *might* be improved
-  uint32_t i;
-  uint32_t c = 0;
-  for(i = 1; i <= n; i++) {
-    if(n % i == 0) {
-      *aui16_at(factors, c) = i;
-      c++;
-    }
-  }
-  aui16_shrink(factors, c);
-  return factors;
-}

+ 0 - 60
src/common/common.h

@@ -1,60 +0,0 @@
-#ifndef COMMON
-#define COMMON
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-typedef int32_t bool;
-
-
-// --------------------------------------------------------------------------
-// String and Printing
-// --------------------------------------------------------------------------
-
-void padString(char *string, uint32_t pad);
-void padStringForInt(char *string, uint32_t val, uint32_t numDigits);
-void sprint_uint(char *string, uint32_t val);
-
-void printError(char *error);
-void sprintBinary_uint8(char *pstring, uint8_t n);
-void sprintBinary_uint64(char *pstring, uint64_t n);
-
-
-// --------------------------------------------------------------------------
-// Math
-// --------------------------------------------------------------------------
-
-uint32_t factorial(uint32_t n);
-
-struct Array_uint16;
-struct Array_uint16 *getPrimeFactors_alloc(uint16_t n);
-struct Array_uint16 *getFactors_alloc(uint16_t n);
-
-
-// --------------------------------------------------------------------------
-// Inline Functions
-// --------------------------------------------------------------------------
-
-inline uint8_t getRowIndex(uint32_t n, uint32_t ind) {
-  return ind / n;
-}
-
-inline uint8_t getColIndex(uint32_t n, uint32_t ind) {
-  return ind % n;
-}
-
-inline uint32_t get2DIndex(uint32_t n, uint32_t row, uint32_t col) {
-  return row * n + col;
-}
-
-inline uint32_t umin(uint32_t a, uint32_t b) {
-  return a < b ? a : b;
-}
-
-inline uint32_t umax(uint32_t a, uint32_t b) {
-  return a < b ? b : a;
-}
-
-#endif

+ 0 - 12
src/common/common_includes.h

@@ -1,12 +0,0 @@
-#ifndef COMMON_INCLUDES
-#define COMMON_INCLUDES
-
-#include "common.h"
-#include "sarray8.h"
-#include "sarray16.h"
-#include "sarray64.h"
-#include "sbitfield.h"
-#include "smap.h"
-#include "sperm.h"
-
-#endif

+ 0 - 349
src/common/sarray16.c

@@ -1,349 +0,0 @@
-#include "sarray16.h"
-
-#include "sarray8.h"
-#include <stdarg.h>
-#include <math.h>
-
-#ifdef STRUCT_HACK // -------------------------------------------------------
-
-Array_uint16 *aui16_alloc(uint32_t size) {
-  Array_uint16 *array = malloc(sizeof(Array_uint16) + size *sizeof(uint16_t));
-#ifdef BOUNDS_CHECK
-  array->_allocSize = size;
-#endif
-  array->size = size;
-  array->data = (uint16_t*) array + sizeof(Array_uint16);
-  return array;
-}
-
-void aui16_free(Array_uint16 *array) {
-  free(array);
-}
-
-#else // --------------------------------------------------------------------
-
-Array_uint16 *aui16_alloc(uint32_t size) {
-  Array_uint16 *array = malloc(sizeof(Array_uint16));
-#ifdef BOUNDS_CHECK
-  array->_allocSize = size;
-#endif
-  array->size = size;
-  array->data = malloc(size * sizeof(uint16_t));
-  return array;
-}
-
-void aui16_free(Array_uint16 *array) {
-  free(array->data);
-  free(array);
-}
-
-#endif // -------------------------------------------------------------------
-
-Array_uint16 *aui16_allocN(uint32_t n, ...) {
-  Array_uint16 *array = aui16_alloc(n);
-  va_list args;
-  va_start(args, n);
-  uint32_t i;
-  for(i = 0; i < n; i++) {
-    array->data[i] = va_arg(args, int);
-  }
-  va_end(args);
-  return array;
-}
-
-Array_uint16 *aui16_alloc1(uint16_t e1) {
-  return aui16_allocN(1, e1);
-}
-Array_uint16 *aui16_alloc2(uint16_t e1, uint16_t e2) {
-  return aui16_allocN(2, e1, e2);
-}
-Array_uint16 *aui16_alloc3(uint16_t e1, uint16_t e2, uint16_t e3) {
-  return aui16_allocN(3, e1, e2, e3);
-}
-Array_uint16 *aui16_alloc4(uint16_t e1, uint16_t e2,
-                           uint16_t e3, uint16_t e4) {
-  return aui16_allocN(4, e1, e2, e3, e4);
-}
-Array_uint16 *aui16_alloc5(uint16_t e1, uint16_t e2, uint16_t e3,
-                           uint16_t e4, uint16_t e5) {
-  return aui16_allocN(5, e1, e2, e3, e4, e5);
-}
-
-Array_uint16 *aui16_allocFromAui8(Array_uint8 *aui8) {
-  Array_uint16 *array = aui16_alloc(aui8->size);
-  uint32_t i;
-  for(i = 0; i < array->size; i++) {
-    *aui16_at(array, i) = *aui8_at(aui8, i);
-  }
-  return array;
-}
-
-// -------------------------------------------------------------------------
-
-void aui16_grow(Array_uint16 *array, uint32_t newSize) {
-#ifdef BOUNDS_CHECK
-  if(array->size > array->_allocSize) {
-    fprintf(stderr, "error: Array_uint16 grow: allocsize=%u, newsize=%u \n",
-	    array->_allocSize, newSize);
-    exit(1);
-  }
-#endif
-  array->size = newSize;
-}
-
-void aui16_shrink(Array_uint16 *array, uint32_t newSize) {
-#ifdef BOUNDS_CHECK
-  if(array->size < newSize) {
-    fprintf(stderr, "error: Array_uint16 shrink: size=%u, newsize=%u \n",
-	    array->size, newSize);
-    exit(1);
-  }
-#endif
-  array->size = newSize;
-}
-
-Array_uint16 *aui16_copy(Array_uint16 *array) {
-  Array_uint16 *copy = aui16_alloc(array->size);
-  uint32_t i;
-  for(i = 0; i < array->size; i++) {
-    *aui16_at(copy, i) = *aui16_at(array, i);
-  }
-  return copy;
-}
-
-void aui16_copyInto(Array_uint16 *to, Array_uint16* from) {
-#ifdef BOUNDS_CHECK
-  if(to->size < from->size) {
-    fprintf(stderr,
-            "error: Array_uint16 copyIntoArray: from->size=%u, to->size=%u",
-            from->size, to->size);
-    exit(1);
-  }
-#endif
-  uint32_t i;
-  for(i = 0; i < from->size; i++) {
-    *aui16_at(to, i) = *aui16_at(from, i);
-  }
-}
-
-
-void aui16_sort(Array_uint16 *a, uint32_t start, uint32_t end) {
-#ifdef BOUNDS_CHECK
-  if(end >= a->size || start >= a->size) {
-    fprintf(stderr, "error: Array_uint16 sort: size=%u, start=%u, end=%u \n",
-	    a->size, start, end);
-    exit(1);
-  }
-#endif
-  uint16_t *base = &a->data[start];
-  uint32_t num = end - start + 1;
-  uint32_t size = sizeof(uint16_t);
-  int32_t lessThanCompare(const void *x, const void *y);
-  qsort(base, num, size, lessThanCompare);
-}
-
-bool aui16_areEqualArrays(Array_uint16 *a, Array_uint16 *b) {
-  if(a->size != b->size) {
-    return 0;
-  }
-  uint32_t i;
-  for(i = 0; i < a->size; i++) {
-    if(*aui16_at(a, i) != *aui16_at(b, i)) {
-      return 0;
-    }
-  }
-  return 1;
-}
-
-bool aui16_haveEqualContent(Array_uint16 *a, Array_uint16 *b) {
-  fprintf(stderr, "error: aui16_haveEqualContent is not implemented yet\n");
-  exit(1);
-}
-
-bool aui16_hasDuplicates(Array_uint16 *array) {
-  uint32_t i, j;
-  uint16_t ele;
-  for(i = 0; i < array->size; i++) {
-    ele = *aui16_at(array, i);
-    for(j = 0; j < i; j++) {
-      if(ele == *aui16_at(array, j)) {
-        return 1;
-      }
-    }
-  }
-  return 0;
-}
-
-uint16_t aui16_getMax(Array_uint16 *array) {
-  uint32_t i;
-  uint16_t ele;
-  uint16_t max = 0;
-  for(i = 0; i < array->size; i++) {
-    ele = *aui16_at(array, i);
-    if(ele > max) {
-      max = ele;
-    }
-  }
-  return max;
-}
-
-uint16_t aui16_getMin(Array_uint16 *array) {
-  uint32_t i;
-  uint16_t ele;
-  uint16_t min = 0xffff;
-  for(i = 0; i < array->size; i++) {
-    if(ele < min) {
-      min = ele;
-    }
-  }
-  return min;
-}
-
-// -------------------------------------------------------------------------
-
-bool aui16_isProperSet(Array_uint16 *array) {
-  return !aui16_hasDuplicates(array);
-}
-
-bool aui16_areEqualSets(Array_uint16 *a, Array_uint16 *b) {
-  return aui16_isSubset(a, b) && aui16_isSubset(b, a);
-}
-
-bool aui16_isSubset(Array_uint16 *sub, Array_uint16 *set) {
-  uint32_t i;
-  for(i = 0; i < sub->size; i++) {
-    if(aui16_indexOf(set, *aui16_at(sub, i)) >= set->size) {
-      return 0;
-    }
-  }
-  return 1;
-}
-
-// -------------------------------------------------------------------------
-
-void aui16_sprintLine(Array_uint16 *arr, char *pstring,
-                      uint32_t indFrom, uint32_t indTo, uint32_t indent,
-                      uint32_t digitPad) {
-  uint32_t i;
-  uint16_t ele;
-  padString(pstring, indent);
-  for(i = indFrom; i < indTo; i++) {
-    ele = *aui16_at(arr, i);
-    padStringForInt(pstring, ele, digitPad);
-    sprintf(pstring + strlen(pstring), "%u", ele);
-    if(i < indTo - 1) {
-      sprintf(pstring + strlen(pstring), ", ");
-    }
-  }
-}
-
-void aui16_sprintToNumWithPad(Array_uint16 *arr, char *pstring,
-                               uint32_t elePerLine, uint32_t indent,
-                               uint32_t digitPad) {
-  if(arr->size == 0) {
-    sprintf(pstring + strlen(pstring), "[   ]");
-    return;
-  }
-  uint32_t n = arr->size;
-  uint32_t numLines = ceil((float) n / elePerLine);
-  uint32_t eleInLastLine = n % elePerLine;
-  uint32_t entrySize = 2 + digitPad;
-  // first line
-  padString(pstring + strlen(pstring), indent); // manual indent b/c "["
-  sprintf(pstring + strlen(pstring), "[ ");
-  aui16_sprintLine(arr, pstring, 0, umin(arr->size, elePerLine), 0, digitPad);
-  uint32_t i;
-  // 1 until before last line
-  for(i = 1; i < numLines - 1; i++) {
-    sprintf(pstring + strlen(pstring), ",\n  ");
-    aui16_sprintLine(arr, pstring, i * elePerLine, (i + 1) * elePerLine,
-                     indent, digitPad);
-  }
-  // last line
-  if(numLines > 1) {
-    sprintf(pstring + strlen(pstring), ",\n  ");
-    aui16_sprintLine(arr, pstring, (numLines - 1) * elePerLine,
-                     umin(arr->size, numLines * elePerLine),
-                     indent, digitPad);
-    if(eleInLastLine > 0) {
-      // pads until the end of the line
-      padString(pstring, (elePerLine - eleInLastLine) * entrySize);
-    }
-  }
-  sprintf(pstring + strlen(pstring), " ]");
-}
-
-void aui16_sprintToNum(Array_uint16 *arr, char *pstring,
-                       uint32_t elePerLine, uint32_t indent) {
-  uint16_t max = aui16_getMax(arr);
-  uint32_t digitPad = max == 0 ? 1 : floor(log10(max)) + 1;
-  aui16_sprintToNumWithPad(arr, pstring, elePerLine, indent, digitPad);
-}
-
-void aui16_sprintToWidth(Array_uint16 *arr, char *pstring, uint32_t width,
-                       uint32_t indent) {
-  uint16_t max = aui16_getMax(arr);
-  uint32_t digitPad = max == 0 ? 1 : floor(log10(max)) + 1;
-  uint32_t entrySize = 2 + digitPad;
-  uint32_t additionalSpace = 2 + 2;
-  if(width < indent + additionalSpace + entrySize) { // not enough line wid
-    return;
-  }
-  uint32_t elePerLine = (width - indent - additionalSpace) / entrySize;
-  aui16_sprintToNumWithPad(arr, pstring, elePerLine, indent, digitPad);
-}
-
-void aui16_sprintDefault(Array_uint16 *arr, char *pstring) {
-  aui16_sprintToWidth(arr, pstring, 80, 0);
-}
-
-void aui16_sprintSquare(Array_uint16 *arr, char *pstring, uint32_t indent) {
-  uint32_t sq = ceil(sqrt(arr->size));
-  aui16_sprintToNum(arr, pstring, sq, indent);
-}
-
-void aui16_printToNum(Array_uint16 *arr,uint32_t elePerLine,uint32_t indent) {
-  char *pstring = malloc(128 + arr->size * 16); // pretty safe guess I think
-  pstring[0] = '\0';
-  aui16_sprintToNum(arr, pstring, elePerLine, indent);
-  printf("%s\n", pstring);
-  free(pstring);
-}
-
-void aui16_printToWidth(Array_uint16 *arr, uint32_t width, uint32_t indent) {
-  char *pstring = malloc(128 + arr->size * 16); // pretty safe guess I think
-  pstring[0] = '\0';
-  aui16_sprintToWidth(arr, pstring, width, indent);
-  printf("%s\n", pstring);
-  free(pstring);
-}
-
-void aui16_printDefault(Array_uint16 *arr) {
-  char *pstring = malloc(128 + arr->size * 16); // pretty safe guess I think
-  pstring[0] = '\0';
-  aui16_sprintDefault(arr, pstring);
-  printf("%s\n", pstring);
-  free(pstring);
-}
-
-void aui16_printSquare(Array_uint16 *arr, uint32_t indent) {
-  char *pstring = malloc(128 + arr->size * 16); // pretty safe guess I think
-  pstring[0] = '\0';
-  aui16_sprintSquare(arr, pstring, indent);
-  printf("%s\n", pstring);
-  free(pstring);
-}
-
-// -------------------------------------------------------------------------
-
-int32_t lessThanCompare(const void *x, const void *y) {
-  uint16_t xx = *(uint16_t*) x;
-  uint16_t yy = *(uint16_t*) y;
-  if(xx < yy) {
-    return -1;
-  }
-  if(xx > yy) {
-    return 1;
-  }
-  return 0;
-}

+ 0 - 190
src/common/sarray16.h

@@ -1,190 +0,0 @@
-#ifndef SARRAY16
-#define SARRAY16
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include "common.h"
-
-/*
-  Array_uint16 is a thin wrapper around a raw uint16_t C-style array. It adds
-  a size attribute and optional BOUNDS_CHECKs. It is possible to tightly
-  pack the struct by setting STRUCT_HACK.
-  If BOUNDS_CHECK is not set, then there should be no overhead to direct
-  array access.
-
-  It is possible to shrink (and grow again) an array (up to its original
-  size).
-
-  Various utility functions are - somewhat inefficiently - implemented.
-
-  Array_uint16 also provides various set functions and can act as a set. This
-  is not enforces however.
-*/
-
-struct Array_uint16 {
-#ifdef BOUNDS_CHECK
-  uint32_t _allocSize;
-#endif
-  uint32_t size;
-  uint16_t *data;
-};
-typedef struct Array_uint16 Array_uint16;
-
-
-// --------------------------------------------------------------------------
-// Alloc / Free
-// --------------------------------------------------------------------------
-
-Array_uint16 *aui16_alloc(uint32_t size);
-Array_uint16 *aui16_alloc1(uint16_t e1);
-Array_uint16 *aui16_alloc2(uint16_t e1, uint16_t e2);
-Array_uint16 *aui16_alloc3(uint16_t e1, uint16_t e2, uint16_t e3);
-Array_uint16 *aui16_alloc4(uint16_t e1, uint16_t e2,
-                                   uint16_t e3, uint16_t e4);
-Array_uint16 *aui16_alloc5(uint16_t e1, uint16_t e2, uint16_t e3,
-                                   uint16_t e4, uint16_t e5);
-Array_uint16 *aui16_allocN(uint32_t n, ...);
-
-struct Array_uint8;
-Array_uint16 *aui16_allocFromAui8(struct Array_uint8 *aui8);
-
-void aui16_free(Array_uint16 *array);
-
-
-// --------------------------------------------------------------------------
-// Management
-// --------------------------------------------------------------------------
-
-void aui16_grow(Array_uint16 *array, uint32_t newSize);
-void aui16_shrink(Array_uint16 *array, uint32_t newSize);
-
-Array_uint16 *aui16_copy(Array_uint16 *array);
-void aui16_copyInto(Array_uint16 *to, Array_uint16* from);
-
-/*
-  Sort between array between [start, end]. Uses qsort from stdlib
- */
-void aui16_sort(Array_uint16 *a, uint32_t start, uint32_t end);
-
-/*
-  Only true if a[i] == b[i] for equal sized arrays and i = 0..a->size
- */
-bool aui16_areEqualArrays(Array_uint16 *a, Array_uint16 *b);
-
-/*
-  Disregards ordering. Still requires equal sizes
- */
-bool aui16_haveEqualContent(Array_uint16 *a, Array_uint16 *b);
-
-bool aui16_hasDuplicates(Array_uint16 *array);
-
-uint16_t aui16_getMax(Array_uint16 *array);
-uint16_t aui16_getMin(Array_uint16 *array);
-
-
-// --------------------------------------------------------------------------
-// Set Functions
-// --------------------------------------------------------------------------
-
-bool aui16_isProperSet(Array_uint16 *a);
-
-/*
-  Disregards ordering and duplicates
- */
-bool aui16_areEqualSets(Array_uint16 *a, Array_uint16 *b);
-
-/*
-  Disregards ordering and duplicates
- */
-bool aui16_isSubset(Array_uint16 *sub, Array_uint16 *set);
-
-
-// --------------------------------------------------------------------------
-// Printing
-// --------------------------------------------------------------------------
-
-/*
-  Sorints the interval [indFrom, indTo) of the array. Pads up to digitPad
-  digits.
-  If startBracket == 1, then the pstring starts with "[ ".
-  If endBracket == 1, then the pstring ends with " ]".
- */
-void aui16_sprintLine(Array_uint16 *arr, char *pstring, uint32_t indFrom,
-                      uint32_t indTo, uint32_t indent, uint32_t digitPad);
-
-/*
-  sprints the array with maximal width = width. Pads the last line to full
-  width (aligned).
- */
-void aui16_sprintToNumWithPad(Array_uint16 *arr, char *pstring,
-                               uint32_t elePerLine, uint32_t indent,
-                               uint32_t digitPad);
-
-/*
-  Take the maximum value of arr for digit pad calculation
- */
-void aui16_sprintToNum(Array_uint16 *arr, char *pstring,
-                       uint32_t elePerLine, uint32_t indent);
-void aui16_sprintToWidth(Array_uint16 *arr, char *pstring,
-                         uint32_t elePerLine, uint32_t indent);
-
-
-/*
-  sprints with width = 80 and indent = 0
- */
-void aui16_sprintDefault(Array_uint16 *arr, char *pstring);
-
-/*
-  sprints the array as a square matrix (row-wise). If array size is not a
-  square number, then then the next biggest integer is taken as square size
- */
-void aui16_sprintSquare(Array_uint16 *arr, char *pstring, uint32_t indent);
-
-void aui16_printToNum(Array_uint16 *arr, uint32_t elePerLine,uint32_t indent);
-void aui16_printToWidth(Array_uint16 *arr, uint32_t width, uint32_t indent);
-void aui16_printDefault(Array_uint16 *arr);
-void aui16_printSquare(Array_uint16 *arr, uint32_t indent);
-
-
-// --------------------------------------------------------------------------
-// Inline Functions
-// --------------------------------------------------------------------------
-
-inline uint16_t *aui16_at(Array_uint16 *array, uint32_t index) {
-#ifdef BOUNDS_CHECK
-  if(index >= array->size) {
-    fprintf(stderr, "error: Array_uint16 out of bounds: size=%u, index=%u \n",
-            array->size, index);
-    exit(1);
-  }
-#endif
-  return &array->data[index];
-}
-
-inline void aui16_fill(Array_uint16 *array, uint16_t val) {
-  uint32_t i;
-  for(i = 0; i < array->size; i++) {
-    *aui16_at(array, i) = val;
-  }
-}
-
-// excludes to
-inline void aui16_setToRange(Array_uint16 *array, uint32_t from,
-                             uint32_t to, uint16_t offset) {
-  uint32_t i;
-  for(i = from; i < to; i++) {
-    *aui16_at(array, i) = offset + i - from;
-  }
-}
-
-// For now: stupid linear search, no error on fail
-inline uint16_t aui16_indexOf(Array_uint16 *array, uint16_t ele) {
-    uint32_t i;
-  for(i = 0; i < array->size; i++) {
-    if(*aui16_at(array, i) == ele) return i;
-  }
-  return 0xffff;
-}
-
-#endif

+ 0 - 31
src/common/sarray64.c

@@ -1,31 +0,0 @@
-#include "sarray64.h"
-
-#ifdef STRUCT_HACK // -------------------------------------------------------
-
-Array_uint16 *aui64_alloc(uint32_t size) {
-  Array_uint64 *array = malloc(sizeof(Array_uint64) + size * sizeof(uint64_t));
-  array->size = size;
-  array->data = (uint64_t*) array + sizeof(Array_uint64);
-  return array;
-}
-
-void aui64_free(Array_uint64 *array) {
-  free(array);
-}
-
-#else // --------------------------------------------------------------------
-
-Array_uint64 *aui64_alloc(uint32_t size) {
-  Array_uint64 *array = malloc(sizeof(Array_uint64));
-  array->size = size;
-  array->data = malloc(size * sizeof(uint64_t));
-  return array;
-}
-
-
-void aui64_free(Array_uint64 *array) {
-  free(array->data);
-  free(array);
-}
-
-#endif // -------------------------------------------------------------------

+ 0 - 42
src/common/sarray64.h

@@ -1,42 +0,0 @@
-#ifndef SARRAY64
-#define SARRAY64
-
-#include "common.h"
-
-/*
-  Array_uint64 is a thin wrapper around a raw uint64_t C-style array.
-
-  For more information, see the uint16_t version in array16.h
-*/
-
-struct Array_uint64 {
-  uint32_t size;
-  uint64_t *data;
-};
-typedef struct Array_uint64 Array_uint64;
-
-
-// --------------------------------------------------------------------------
-// Alloc / Free
-// --------------------------------------------------------------------------
-
-Array_uint64 *aui64_alloc(uint32_t size);
-void aui64_free(Array_uint64 *array);
-
-
-// --------------------------------------------------------------------------
-// Inline Functions
-// --------------------------------------------------------------------------
-
-inline uint64_t *aui64_at(Array_uint64 *array, uint32_t index) {
-#ifdef BOUNDS_CHECK
-  if(index >= array->size) {
-    fprintf(stderr, "error: Array_uint64 out of bounds: size=%u, index=%u \n",
-            array->size, index);
-    exit(1);
-  }
-#endif
-  return &array->data[index];
-}
-
-#endif

+ 0 - 99
src/common/sarray8.c

@@ -1,99 +0,0 @@
-#include "sarray8.h"
-
-#include "sarray16.h"
-#include <stdarg.h>
-
-#ifdef STRUCT_HACK // -------------------------------------------------------
-
-Array_uint8 *aui8_alloc(uint32_t size) {
-  Array_uint8 *array = malloc(sizeof(Array_uint8) + size * sizeof(uint8_t));
-  array->size = size;
-  array->data = (uint8_t*) array + sizeof(Array_uint8);
-  return array;
-}
-
-void aui8_free(Array_uint8 *array) {
-  free(array);
-}
-
-#else // --------------------------------------------------------------------
-
-Array_uint8 *aui8_alloc(uint32_t size) {
-  Array_uint8 *array = malloc(sizeof(Array_uint8));
-  array->size = size;
-  array->data = malloc(size * sizeof(uint8_t));
-  return array;
-}
-
-void aui8_free(Array_uint8 *array) {
-  free(array->data);
-  free(array);
-}
-
-#endif // -------------------------------------------------------------------
-
-
-Array_uint8 *aui8_allocN(uint32_t n, ...) {
-  Array_uint8 *array = aui8_alloc(n);
-  va_list args;
-  va_start(args, n);
-  uint32_t i;
-  for(i = 0; i < n; i++) {
-    array->data[i] = va_arg(args, int);
-  }
-  va_end(args);
-  return array;
-}
-
-// --------------------------------------------------------------------------
-
-void aui8_sprintToNum(Array_uint8 *arr, char *pstring,
-                      uint32_t elePerLine, uint32_t indent) {
-  Array_uint16 *aui16 = aui16_allocFromAui8(arr);
-  aui16_sprintToNum(aui16, pstring, elePerLine, indent);
-  aui16_free(aui16);
-
-}
-
-void aui8_sprintToWidth(Array_uint8 *arr, char *pstring,
-                        uint32_t width, uint32_t indent) {
-  Array_uint16 *aui16 = aui16_allocFromAui8(arr);
-  aui16_sprintToWidth(aui16, pstring, width, indent);
-  aui16_free(aui16);
-}
-
-void aui8_sprintDefault(Array_uint8 *arr, char *pstring) {
-  Array_uint16 *aui16 = aui16_allocFromAui8(arr);
-  aui16_sprintDefault(aui16, pstring);
-  aui16_free(aui16);
-}
-
-void aui8_sprintSquare(Array_uint8 *arr, char *pstring, uint32_t indent) {
-  Array_uint16 *aui16 = aui16_allocFromAui8(arr);
-  aui16_sprintSquare(aui16, pstring, indent);
-  aui16_free(aui16);
-}
-
-void aui8_printToNum(Array_uint8 *arr, uint32_t elePerLine, uint32_t indent) {
-  Array_uint16 *aui16 = aui16_allocFromAui8(arr);
-  aui16_printToNum(aui16, elePerLine, indent);
-  aui16_free(aui16);
-}
-
-void aui8_printToWidth(Array_uint8 *arr, uint32_t width, uint32_t indent) {
-  Array_uint16 *aui16 = aui16_allocFromAui8(arr);
-  aui16_printToWidth(aui16, width, indent);
-  aui16_free(aui16);
-}
-
-void aui8_printDefault(Array_uint8 *arr) {
-  Array_uint16 *aui16 = aui16_allocFromAui8(arr);
-  aui16_printDefault(aui16);
-  aui16_free(aui16);
-}
-
-void aui8_printSquare(Array_uint8 *arr, uint32_t indent) {
-  Array_uint16 *aui16 = aui16_allocFromAui8(arr);
-  aui16_printSquare(aui16, indent);
-  aui16_free(aui16);
-}

+ 0 - 67
src/common/sarray8.h

@@ -1,67 +0,0 @@
-#ifndef SARRAY8
-#define SARRAY8
-
-#include <stdio.h>
-#include "common.h"
-
-/*
-  Array_uint16 is a thin wrapper around a raw uint8_t C-style array.
-
-  For more information, see the uint16_t version in array16.h
-*/
-
-struct Array_uint8 {
-  uint32_t size;
-  uint8_t *data;
-};
-typedef struct Array_uint8 Array_uint8;
-
-
-// --------------------------------------------------------------------------
-// Alloc / Free
-// --------------------------------------------------------------------------
-
-Array_uint8 *aui8_alloc(uint32_t size);
-Array_uint8 *aui8_allocN(uint32_t n, ...);
-
-void aui8_free(Array_uint8 *array);
-
-
-// --------------------------------------------------------------------------
-// Printing
-// --------------------------------------------------------------------------
-
-/*
-  See sarray16.h for documentation. Array_uint8 are simply converted to
-  Array_uint16 and then are printed as such.
- */
-
-void aui8_sprintToNum(Array_uint8 *arr, char *pstring,
-                      uint32_t elePerLine, uint32_t indent);
-void aui8_sprintToWidth(Array_uint8 *arr, char *pstring,
-                        uint32_t elePerLine, uint32_t indent);
-void aui8_sprintDefault(Array_uint8 *arr, char *pstring);
-void aui8_sprintSquare(Array_uint8 *arr, char *pstring, uint32_t indent);
-
-void aui8_printToNum(Array_uint8 *arr, uint32_t elePerLine,uint32_t indent);
-void aui8_printToWidth(Array_uint8 *arr, uint32_t width, uint32_t indent);
-void aui8_printDefault(Array_uint8 *arr);
-void aui8_printSquare(Array_uint8 *arr, uint32_t indent);
-
-
-// --------------------------------------------------------------------------
-// Inline Functions
-// --------------------------------------------------------------------------
-
-inline uint8_t *aui8_at(Array_uint8 *array, uint32_t index) {
-#ifdef BOUNDS_CHECK
-  if(index >= array->size) {
-    fprintf(stderr, "error: Array_uint8 out of bounds: size=%u, index=%u \n",
-	    array->size, index);
-    exit(1);
-  }
-#endif
-  return &array->data[index];
-}
-
-#endif

+ 0 - 32
src/common/sbitfield.c

@@ -1,32 +0,0 @@
-#include "sbitfield.h"
-
-Bitfield *bitfield_alloc(uint32_t bitCount) {
-  Bitfield *bf = malloc(sizeof(Bitfield));
-  bf->bitCount = bitCount;
-  bf->array = aui64_alloc(1 + bitCount / 64);
-  return bf;
-}
-
-void bitfield_free(Bitfield *bf) {
-  aui64_free(bf->array);
-  free(bf);
-}
-
-// --------------------------------------------------------------------------
-
-void bitfield_sprint(char *pstring, Bitfield *bf) {
-  pstring[bf->bitCount] = '\0';
-  uint32_t i;
-  for(i = 0; i < bf->bitCount; i++) {
-    if(bitfield_testBit(bf, i) == 0) {
-      pstring[bf->bitCount - i - 1] = '0';
-    } else {
-      pstring[bf->bitCount - i - 1] = '1';
-    }
-  }
-}
-
-void bitfield_print(char *pstring, Bitfield *bf) {
-  bitfield_sprint(pstring, bf);
-  printf("%s\n", pstring);
-}

+ 0 - 178
src/common/sbitfield.h

@@ -1,178 +0,0 @@
-#ifndef SBITFIELD
-#define SBITFIELD
-
-#include <stdio.h>
-#include "sarray64.h"
-
-/*
-  In a Bitfield individual bits can be maniuplated. This can be used for
-  storage-efficient masks.
-
-  The implementation is based on Array_uint64.
-
-  The functions
-    bitfield_trailingZeros
-    bitfield_sumBits
-    bitfield_leadingZeros
-  are dependet on GCC built-ins and currently only available with GCC
- */
-
-struct Bitfield {
-  uint32_t bitCount;
-  Array_uint64 *array;
-};
-typedef struct Bitfield Bitfield;
-
-
-// --------------------------------------------------------------------------
-// Alloc / Free
-// --------------------------------------------------------------------------
-
-Bitfield *bitfield_alloc(uint32_t bitCount);
-void bitfield_free(Bitfield *bf);
-
-
-// --------------------------------------------------------------------------
-// Printing
-// --------------------------------------------------------------------------
-
-void bitfield_sprint(char *pstring, struct Bitfield *bf);
-void bitfield_print(char *pstring, struct Bitfield *bf);
-
-
-// --------------------------------------------------------------------------
-// Inline Functions
-// --------------------------------------------------------------------------
-
-inline void bitfield_clear(Bitfield *bf) {
-  uint32_t i;
-  for(i = 0; i < bf->array->size; i++) {
-    *aui64_at(bf->array, i) = 0;
-  }
-}
-
-inline void bitfield_setBit(Bitfield *bf, const uint32_t index) {
-#ifdef BOUNDS_CHECK
-  if(index >= bf->bitCount) {
-    fprintf(stderr,
-            "error: Bitfield setBit out of bounds: size=%u, index=%u \n",
-	    bf->bitCount, index);
-    exit(1);
-  }
-#endif
-  *aui64_at(bf->array, index / 64) |= (1 << (index % 64));
-}
-
-inline void bitfield_unsetBit(Bitfield *bf, const uint32_t index) {
-#ifdef BOUNDS_CHECK
-  if(index >= bf->bitCount) {
-    fprintf(stderr,
-            "error: Bitfield unsetBit out of bounds: size=%u, index=%u \n",
-	    bf->bitCount, index);
-    exit(1);
-  }
-#endif
-  *aui64_at(bf->array, index / 64) &= ~(1 << (index % 64));
-}
-
-inline void bitfield_toggleBit(Bitfield *bf, const uint32_t index) {
-#ifdef BOUNDS_CHECK
-  if(index >= bf->bitCount) {
-    fprintf(stderr,
-            "error: Bitfield toogleBit out of bounds: size=%u, index=%u \n",
-	    bf->bitCount, index);
-    exit(1);
-  }
-#endif
-  *aui64_at(bf->array, index / 64) ^= (1 << (index % 64));
-}
-
-inline void bitfield_placeBit(Bitfield *bf, const uint32_t index,
-                              const uint32_t b) {
-#ifdef BOUNDS_CHECK
-  if(index >= bf->bitCount) {
-    fprintf(stderr,
-            "error: Bitfield toogleBit out of bounds: size=%u, index=%u \n",
-	    bf->bitCount, index);
-    exit(1);
-  }
-  if(b != 0 && b != 1) {
-    fprintf(stderr, "error: Bitfield placeBit bit is not 0 or 1 but %u\n",
-            b);
-    exit(1);
-  }
-#endif
-  if(b == 0) {
-    bitfield_unsetBit(bf, index);
-  } else {
-    bitfield_setBit(bf, index);
-  }
-}
-
-inline uint32_t bitfield_testBit(Bitfield *bf, const uint32_t index) {
-#ifdef BOUNDS_CHECK
-  if(index >= bf->bitCount) {
-    fprintf(stderr,
-            "error: Bitfield toogleBit out of bounds: size=%u, index=%u \n",
-	    bf->bitCount, index);
-    exit(1);
-  }
-#endif
-  return ((*aui64_at(bf->array, index / 64)) >> (index % 64)) & 1;
-}
-
-#ifdef __GNUC__ // ---------------------------------------------------------
-
-inline uint32_t bitfield_sumBits(Bitfield *bf) {
-  uint32_t sum = 0;
-  uint32_t i;
-  for(i = 0; i < bf->array->size; i++) {
-    sum += __builtin_popcountll(*aui64_at(bf->array, i));
-  }
-  return sum;
-}
-
-inline uint32_t bitfield_trailingZeros(Bitfield *bf) {
-  uint32_t i;
-  uint64_t ele;
-  for(i = 0; i < bf->array->size; i++) {
-    ele = *aui64_at(bf->array, i);
-    if(ele == 0) {
-      continue;
-    }
-    return i * 64 + __builtin_ctzll(ele);
-  }
-}
-
-inline uint32_t bitfield_leadingZeros(Bitfield *bf) {
-  int32_t i;
-  uint64_t ele;
-  for(i = bf->array->size - 1; i >= 0; i--) {
-    ele = *aui64_at(bf->array, i);
-    if(ele == 0) {
-      continue;
-    }
-    return i * 64 + __builtin_clzll(ele) - (64 - bf->bitCount);
-  }
-}
-
-#else // -------------------------------------------------------------------
-
-inline uint32_t sumBits(Bitfield *bf) {
-  fprintf(stderr, "error: Bitfield sumBits is not implemented yet.\n");
-  exit(1);
-}
-
-inline uint32_t trailingZeros(Bitfield *bf) {
-  fprintf(stderr, "error: Bitfield trailingZeros is not implemented yet.\n");
-  exit(1);
-}
-
-inline uint32_t leadingZeros(Bitfield *bf) {
-  fprintf(stderr, "error: Bitfield leadingZeros is not implemented yet.\n");
-  exit(1);
-}
-
-#endif // ------------------------------------------------------------------
-
-#endif

+ 0 - 268
src/common/smap.c

@@ -1,268 +0,0 @@
-#include "smap.h"
-
-#include <math.h>
-
-Map_uint16 *mapui16_alloc(uint32_t size, bool indexed) {
-  Map_uint16 *map = malloc(sizeof(Map_uint16));
-  map->indexed = indexed;
-  map->domain = aui16_alloc(size);
-  map->codomain = aui16_alloc(size);
-  return map;
-}
-
-Map_uint16 *mapui16_alloc_ref(uint32_t size, bool indexed,
-                              Array_uint16 *domain,
-                              Array_uint16 *codomain) {
-  Map_uint16 *map = malloc(sizeof(Map_uint16));
-  map->indexed = indexed;
-  map->domain = domain;
-  map->codomain = codomain;
-  return map;
-}
-
-void mapui16_free(Map_uint16 *map) {
-  aui16_free(map->codomain);
-  aui16_free(map->domain);
-  free(map);
-}
-
-void mapui16_free_ref(Map_uint16 *map) {
-  free(map);
-}
-
-// -------------------------------------------------------------------------
-
-
-void mapui16_mapArray(Map_uint16 *map, Array_uint16 *from, Array_uint16 *to) {
-  uint32_t i;
-  for(i = 0; i < from->size; i++) {
-    *aui16_at(to, i) = mapui16_mapEle(map, *aui16_at(from, i));
-  }
-}
-
-void mapui16_toId(Map_uint16 *map) {
-  map->indexed = 1;
-  uint16_t i;
-  for(i = 0; i < map->domain->size; i++) {
-    *aui16_at(map->domain, i) = i;
-    *aui16_at(map->codomain, i) = i;
-  }
-}
-
-bool mapui16_isValid(Map_uint16 *map) {
-  uint32_t i, j;
-  uint32_t n = map->domain->size;
-  if(n != map->codomain->size) {
-    return 0;
-  }
-  for(i = 0; i < n; i++) {
-    for(j = 0; j < i; j++) {
-      if(*aui16_at(map->domain, i) == *aui16_at(map->domain, j)) {
-        return 0;
-      }
-    }
-    if(*aui16_at(map->codomain, i) == 0xffff ||
-       *aui16_at(map->domain, i) == 0xffff) {
-      return 0;
-    }
-  }
-  return 1;
-}
-
-bool mapui16_areEqual(Map_uint16 *f, Map_uint16 *g) {
-  if(f->domain->size != g->domain->size) {
-    return 0;
-  }
-  if(f->indexed && g->indexed) {
-    return aui16_areEqualArrays(f->codomain, g->codomain);
-  }
-  uint32_t i, ind;
-  for(i = 0; i < f->domain->size; i++) {
-    ind = aui16_indexOf(g->domain, *aui16_at(f->domain, i));
-    if(ind == 0xffff) { // ele does not exist in domain of g
-      return 0;
-    }
-    if(mapui16_mapInd(f, i) != mapui16_mapInd(g, ind)) { // f(ele) != g(ele)
-      return 0;
-    }
-  }
-  return 1;
-}
-
-bool mapui16_areComposable(Map_uint16 *f, Map_uint16 *g) {
-  uint32_t i;
-  for(i = 0; i < g->codomain->size; i++) {
-    if(aui16_indexOf(f->domain, *aui16_at(g->codomain, i)) == 0xffff) {
-      return 0;
-    }
-  }
-  return 1;
-}
-
-bool mapui16_isSurjectiveIn(Map_uint16 *map, Array_uint16 *set) {
-  return aui16_isSubset(set, map->codomain);
-}
-
-bool mapui16_isInjective(Map_uint16 *map) {
-  return !aui16_hasDuplicates(map->codomain);
-}
-
-void mapui16_comp_noalloc(Map_uint16 *f, Map_uint16 *g, Map_uint16 *comp,
-                          bool setDomain) {
-  uint32_t i;
-  for(i = 0; i < g->domain->size; i++) {
-    if(setDomain) {
-      *aui16_at(comp->domain, i) = *aui16_at(g->domain, i);
-    }
-    *aui16_at(comp->codomain, i) = mapui16_mapEle(f, mapui16_mapInd(g, i));
-  }
-}
-
-Map_uint16 *mapui16_comp_alloc(Map_uint16 *f, Map_uint16 *g) {
-  Map_uint16 *comp = mapui16_alloc(g->domain->size, g->indexed);
-  mapui16_comp_noalloc(f, g, comp, 0);
-  return comp;
-}
-
-bool mapui16_hasNotfixedPoints(Map_uint16 *map) {
-  uint32_t i;
-  for(i = 0; i < map->domain->size; i++) {
-    if(*aui16_at(map->domain, i) != mapui16_mapInd(map, i)) {
-      return 1;
-    }
-  }
-  return 0;
-}
-
-uint16_t mapui16_getMaximalNotfixedImage(Map_uint16 *map) {
-#ifdef BOUNDS_CHECK
-  if(!mapui16_hasNotfixedPoints(map)) {
-    printError("mapui16: has no notfixed point!");
-    exit(1);
-  }
-#endif
-  uint32_t i;
-  uint16_t max = 0;
-  uint16_t ele;
-  for(i = 0; i < map->domain->size; i++) {
-    ele = *aui16_at(map->domain, i);
-    if(mapui16_mapInd(map, i) != ele) {
-      max = umax(mapui16_mapInd(map, i), max);
-    }
-  }
-  return max;
-}
-
-// -------------------------------------------------------------------------
-
-void mapui16_sprintLine(Map_uint16 *map, char *pstring, uint32_t indFrom,
-                        uint32_t indTo, uint32_t indent, uint32_t digitPad) {
-  aui16_sprintLine(map->domain, pstring, indFrom, indTo, indent, digitPad);
-  sprintf(pstring + strlen(pstring), "\n");
-  aui16_sprintLine(map->codomain, pstring, indFrom, indTo, indent, digitPad);
-}
-
-// mostly c/p sarray aui16_sprintToNum
-void mapui16_sprintToNum(Map_uint16 *map, char *pstring,
-                         uint32_t elePerLine, uint32_t indent) {
-  if(map->domain->size == 0) {
-    sprintf(pstring + strlen(pstring), "<   ]");
-    return;
-  }
-  Array_uint16 *dom = map->domain;
-  Array_uint16 *cod = map->codomain;
-  uint32_t max = umax(aui16_getMax(dom), aui16_getMax(cod));
-  uint32_t digitPad = max == 0 ? 1 : floor(log10(max)) + 1;
-  uint32_t n = dom->size;
-  uint32_t numLines = ceil((float) n / elePerLine);
-  uint32_t eleInLastLine = n % elePerLine;
-  uint32_t entrySize = 2 + digitPad;
-  // first line
-  padString(pstring + strlen(pstring), indent); // manual indent b/c "<"
-  sprintf(pstring + strlen(pstring), "< ");
-  aui16_sprintLine(dom, pstring, 0, umin(dom->size, elePerLine), 0, digitPad);
-  if(numLines == 1) {
-    sprintf(pstring + strlen(pstring), " >\n");
-  } else {
-    sprintf(pstring + strlen(pstring), ",\n");
-  }
-  padString(pstring + strlen(pstring), indent);
-  sprintf(pstring + strlen(pstring), "< ");
-  aui16_sprintLine(cod, pstring, 0, umin(cod->size, elePerLine), 0, digitPad);
-  if(numLines == 1) {
-    sprintf(pstring + strlen(pstring), " >");
-  }
-  uint32_t i;
-  // 1 until before last line
-  for(i = 1; i < numLines - 1; i++) {
-    sprintf(pstring + strlen(pstring), ",\n\n  ");
-    aui16_sprintLine(dom, pstring, i * elePerLine, (i + 1) * elePerLine,
-                     indent, digitPad);
-    sprintf(pstring + strlen(pstring), ",\n  ");
-    aui16_sprintLine(cod, pstring, i * elePerLine, (i + 1) * elePerLine,
-                     indent, digitPad);
-  }
-  // last line
-  if(numLines > 1) {
-    sprintf(pstring + strlen(pstring), ",\n\n  ");
-    aui16_sprintLine(dom, pstring, (numLines - 1) * elePerLine,
-                     umin(dom->size, numLines * elePerLine),
-                     indent, digitPad);
-    if(eleInLastLine > 0) {
-      padString(pstring, (elePerLine - eleInLastLine) * entrySize);
-    }
-    sprintf(pstring + strlen(pstring), " >\n  ");
-    aui16_sprintLine(cod, pstring, (numLines - 1) * elePerLine,
-                     umin(cod->size, numLines * elePerLine),
-                     indent, digitPad);
-    if(eleInLastLine > 0) {
-      padString(pstring, (elePerLine - eleInLastLine) * entrySize);
-    }
-    sprintf(pstring + strlen(pstring), " >");
-  }
-}
-
-void mapui16_sprintToWidth(Map_uint16 *map, char *pstring,
-                           uint32_t width, uint32_t indent) {
-  // inefficient b/c computes again in sprintToNum but whatever
-  uint32_t max = umax(aui16_getMax(map->domain), aui16_getMax(map->codomain));
-  uint32_t digitPad = max == 0 ? 1 : floor(log10(max)) + 1;
-  uint32_t entrySize = 2 + digitPad;
-  uint32_t additionalSpace = 2 + 2;
-  if(width < indent + additionalSpace + entrySize) { // not enough line wid
-    return;
-  }
-  uint32_t elePerLine = (width - indent - additionalSpace) / entrySize;
-  mapui16_sprintToNum(map, pstring, elePerLine, indent);
-}
-
-void mapui16_sprintDefault(Map_uint16 *map, char *pstring) {
-  mapui16_sprintToWidth(map, pstring, 80, 0);
-}
-
-void mapui16_printToNum(Map_uint16 *map,uint32_t elePerLine,uint32_t indent) {
-  uint32_t n = map->domain->size;
-  char *pstring = malloc(128 + n * 16 * 2); // pretty safe guess I tk
-  pstring[0] = '\0';
-  mapui16_sprintToNum(map, pstring,  elePerLine, indent);
-  printf("%s\n", pstring);
-  free(pstring);
-}
-
-void mapui16_printToWidth(Map_uint16 *map, uint32_t width, uint32_t indent) {
-  uint32_t n = map->domain->size;
-  char *pstring = malloc(128 + n * 16 * 2); // pretty safe guess I tk
-  pstring[0] = '\0';
-  mapui16_sprintToWidth(map, pstring, width, indent);
-  printf("%s\n", pstring);
-  free(pstring);
-}
-
-void mapui16_printDefault(Map_uint16 *map) {
-  uint32_t n = map->domain->size;
-  char *pstring = malloc(128 + n * 16 * 2); // pretty safe guess I tk
-  pstring[0] = '\0';
-  mapui16_sprintDefault(map, pstring);
-  printf("%s\n", pstring);
-  free(pstring);
-}

+ 0 - 129
src/common/smap.h

@@ -1,129 +0,0 @@
-#ifndef SBIMAP
-#define SBIMAP
-
-#include "common.h"
-#include "sarray16.h"
-
-/*
-  Representation of a discrete map. Even if the map is not 1:1, always an
-  element of index i in the domain maps to codomain[i].
-
-  For a map to be valid it is required that
-    domain->size == codomain->size
-    domain contains no duplicates, no 0xffff
-    codomain contains no 0xffff
-*/
-
-struct Map_uint16 {
-  bool indexed;
-  Array_uint16 *domain;
-  Array_uint16 *codomain;
-};
-typedef struct Map_uint16 Map_uint16;
-
-
-// --------------------------------------------------------------------------
-// Alloc / Free
-// --------------------------------------------------------------------------
-
-Map_uint16 *mapui16_alloc(uint32_t size, bool indexed);
-Map_uint16 *mapui16_alloc_ref(uint32_t size, bool indexed,
-                              Array_uint16 *domain, Array_uint16 *codomain);
-void mapui16_free(Map_uint16 *map);
-void mapui16_free_ref(Map_uint16 *map);
-
-
-// --------------------------------------------------------------------------
-// MapU
-// --------------------------------------------------------------------------
-
-void mapui16_mapArray(Map_uint16 *map, Array_uint16 *from, Array_uint16 *to);
-
-void mapui16_toId(Map_uint16 *map);
-
-bool mapui16_isValid(Map_uint16 *map);
-
-bool mapui16_areEqual(Map_uint16 *f, Map_uint16 *g);
-
-/*
-  For maps to be composable it is required that
-  g->codomain is subset of f->domain
-*/
-bool mapui16_areComposable(Map_uint16 *f, Map_uint16 *g);
-
-bool mapui16_isSurjectiveIn(Map_uint16 *map, Array_uint16 *set);
-bool mapui16_isInjective(Map_uint16 *map);
-
-/*
-  g->domain->size must be equal to comp->domain->size to get a valid map
-  If setDomain == 0, then comp->domain will be left untouched
-*/
-void mapui16_comp_noalloc(Map_uint16 *f, Map_uint16 *g, Map_uint16 *comp,
-                          bool setDomain);
-
-Map_uint16 *mapui16_comp_alloc(Map_uint16 *f, Map_uint16 *g);
-
-/*
-  A notfixed point is a point with x != f(x)
-*/
-bool mapui16_hasNotfixedPoints(Map_uint16 *map);
-
-/*
-  If there are no notfixed points (i.e. map is id) then this returns 0 which
-  is a wrong result. Always call hasNotfixedPoint beforehand to make sure.
-*/
-uint16_t mapui16_getMaximalNotfixedImage(Map_uint16 *map);
-
-
-// --------------------------------------------------------------------------
-// Printing
-// --------------------------------------------------------------------------
-
-/*
-  For doc see sarray.h. The formatting looks like this:
-
-  <   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,
-  < 123,  44,   5,   0, 123,  34,  42,  44, 432,   1,   0,
-
-     12,  13,  14,  15                                     >
-      0, 132,  42,  43                                     >
-
-  Note that the padding should be the maximum of pad for the domain / codomain
-  range to have it nicely aligned.
-*/
-
-void mapui16_sprintLine(Map_uint16 *map, char *pstring, uint32_t indFrom,
-                        uint32_t indTo, uint32_t indent, uint32_t digitPad);
-
-void mapui16_sprintToNum(Map_uint16 *map, char *pstring,
-                         uint32_t elePerLine, uint32_t indent);
-void mapui16_sprintToWidth(Map_uint16 *map, char *pstring,
-                           uint32_t width, uint32_t indent);
-void mapui16_sprintDefault(Map_uint16 *map, char *pstring);
-
-void mapui16_printToNum(Map_uint16 *map, uint32_t elePerLine,uint32_t indent);
-void mapui16_printToWidth(Map_uint16 *map, uint32_t width, uint32_t indent);
-void mapui16_printDefault(Map_uint16 *map);
-
-// --------------------------------------------------------------------------
-// Inline Functions
-// --------------------------------------------------------------------------
-
-inline uint16_t mapui16_mapEle(Map_uint16 *map, uint16_t ele) {
-  uint32_t index;
-  if(map->indexed) {
-    index = ele;
-  } else {
-    index = aui16_indexOf(map->domain, ele);
-  }
-  return *aui16_at(map->codomain, index);
-}
-
-/*
-  Maps from index to element
- */
-inline uint16_t mapui16_mapInd(Map_uint16 *map, uint32_t ind) {
-  return *aui16_at(map->codomain, ind);
-}
-
-#endif

+ 0 - 103
src/common/sperm.c

@@ -1,103 +0,0 @@
-#include "sperm.h"
-
-#include "sarray16.h"
-
-void binom_init(Array_uint16 *array, uint16_t n) {
-  aui16_fill(array, 0xffff);
-  aui16_setToRange(array, 0, n, 0);
-}
-
-void perm_init(Array_uint16 *array) {
-  aui16_setToRange(array, 0, array->size, 0);
-}
-
-/*
-  since the binom can be 0xffff terminated, more complicated cases need to be
-  considered (ie. is t0 end element / is t1 end element)
-*/
-bool binom_shiftDefault(Array_uint16 *array, uint16_t max) {
-  uint32_t n = 0;
-  uint32_t i;
-  for(i = 0; i < array->size; i++) {
-    if(*aui16_at(array, i) == 0xffff) {
-      break;
-    } else {
-      n++;
-    }
-  }
-  return binom_shift(array, 0, max, 0, n);
-}
-
-bool binom_shift(Array_uint16 *array, uint16_t min, uint16_t max,
-                 uint16_t offset, uint16_t n) {
-  uint32_t i;
-  uint16_t *ele_i;
-  uint16_t *ele_im1;
-  for(i = offset + 1; i < offset + n; i++) {
-    ele_i = aui16_at(array, i);
-    ele_im1 = aui16_at(array, i - 1);
-    if(*ele_i - *ele_im1 > 1) { // inc i - 1 if possible
-      (*ele_im1)++;
-      aui16_setToRange(array, offset, i - 1, min); // reset before i - 1
-      return !(i == offset + 1 && *ele_im1 == max - n + 1);
-    }
-    if(i == offset + n - 1 && *ele_i < max) { // inc last ele if possible?
-      (*ele_i)++;
-      aui16_setToRange(array, offset, i, min); // reset before last ele
-      return 1;
-    }
-  }
-  return 0;
-}
-
-uint32_t binom_getK(Array_uint16 *array) {
-  uint32_t i;
-  for(i = 0; i < array->size; i++) {
-    if(*aui16_at(array, i) == 0xffff) {
-      return i;
-    }
-  }
-  return array->size;
-}
-
-uint16_t nextBiggestInd(Array_uint16 *array, uint32_t pos, uint32_t to) {
-  uint16_t curr = *aui16_at(array, pos);
-  uint16_t cand = 0xffff;
-  uint16_t ind = 0xffff;
-  uint32_t i;
-  uint16_t ele;
-  for(i = pos + 1; i < to; i++) {
-    ele = *aui16_at(array, i);
-    if(ele > curr && ele < cand) {
-      cand = ele;
-      ind = i;
-    }
-  }
-  return ind;
-}
-
-void switchElements(Array_uint16 *array, uint32_t ind1, uint32_t ind2) {
-  uint16_t ele = *aui16_at(array, ind1);
-  *aui16_at(array, ind1) = *aui16_at(array, ind2);
-  *aui16_at(array, ind2) = ele;
-}
-
-bool perm_shiftDefault(Array_uint16 *array) {
-  return perm_shift(array, 0, array->size);
-}
-
-bool perm_shift(Array_uint16 *array, uint16_t from, uint16_t to) {
-  int32_t pos = to - 2;
-  uint16_t nbi;
-  while(pos >= from) {
-    nbi = nextBiggestInd(array, pos, to);
-    if(nbi != 0xffff) {
-      switchElements(array, pos, nbi);
-      aui16_sort(array, pos + 1, to - 1);
-      return 1;
-    } else {
-      pos--;
-    }
-  }
-  return 0;
-}

+ 0 - 88
src/common/sperm.h

@@ -1,88 +0,0 @@
-#ifndef SPERM
-#define SPERM
-
-#include "common.h"
-
-struct Array_uint16;
-
-
-// --------------------------------------------------------------------------
-// Binomial-like functions to systemtically test combinations of ints
-// --------------------------------------------------------------------------
-
-/*
-  Fills the array with 0xffff and fills to id = (0 1 2 3 ... n - 1 0xffff ...)
-  before (excluding) index n
- */
-void binom_init(struct Array_uint16 *array, uint16_t n);
-
-/*
-  Shifts the array by one step (if possible) according to the following scheme:
-    1. [ a b ... x [x + >= 2] ... ]      -> [ 0 1 ... [x + 1] [x + >= 2] ... ]
-    2. [ a b ... x [x + 1] 0xffff ... ]  -> [ 0 1 ... x [x + 2 < max] ...]
-    3. [ 0 1 ... [max - 2] [max - 1] 0xffff ...]   -> no action
-  For example n = 3, max = 5
-    ( 0 1 2 0xffff ...) -> (case 2)
-    ( 0 1 3 0xffff ...) ->
-    ( 0 2 3 0xffff ...) ->
-    ( 1 2 3 0xffff ...) -> (case 2)
-    ( 0 1 4 0xffff ...) ->
-    ( 0 2 4 0xffff ...) ->
-    ( 1 2 4 0xffff ...) ->
-    ( 0 3 4 0xffff ...) ->
-    ( 1 3 4 0xffff ...) ->
-    ( 2 3 4 0xffff ...) -> (case 3)
-  Input:
-    array -  array of the form a[0] < a[1] < ... < a[n-1], 0xffff, 0xffff, ...
-    max   -  1 + maximal element to occur in array (ie. array[<n] < max)
-  Return:
-    1  -  if shift was possible (case 1, 2)
-    0  -  if shift was impossible (case 3)
-*/
-bool binom_shiftDefault(struct Array_uint16 *array, uint16_t max);
-
-/*
-  More general version of the scheme above
-    > uses numbers in [min, max)
-    > offsets the array by start until end
- */
-bool binom_shift(struct Array_uint16 *array, uint16_t min, uint16_t max,
-                 uint16_t offset, uint16_t n);
-
-/*
-  Returns the current k of ("n over k"), i.e. the number of non 0xffff elements
-  in array.
- */
-uint32_t binom_getK(struct Array_uint16 *array);
-
-
-// --------------------------------------------------------------------------
-// Permutation-like function
-// --------------------------------------------------------------------------
-
-/*
- * Fills the whole array with id = (0 1 2 3 ... array->size - 1)
- */
-void perm_init(struct Array_uint16 *array);
-
-
-/*
-  Shifts the array by one step towards the "numerical" maximum value if
-  you take the elements of the array as digits of a number
-  For Example:
-    ( 0 1 2 3 ) ->
-    ( 0 1 3 2 ) ->
-    ( 0 2 1 3 ) ->
-    ( 0 2 3 1 ) ->
-    ( 1 0 2 3 ) ->
-    ( 1 0 3 2 ) ->
-    ...
- */
-bool perm_shiftDefault(struct Array_uint16 *array);
-
-/*
-  Shifts the permutation between [from, to) as described in the default version
- */
-bool perm_shift(struct Array_uint16 *array, uint16_t from, uint16_t to);
-
-#endif

+ 0 - 247
src/gen/asocgen.c

@@ -1,247 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "asocgen.h"
-
-Zip *allocZip(uint8_t n) {
-  Zip *zip = malloc(sizeof(Zip));
-  zip->n = n;
-  zip->pos = 1;
-  zip->lastEntry = 0;
-  zip->iord = aui8_alloc((n - 1) * (n - 1));
-  zip->candidates = aui8_alloc(n);
-  return zip;
-}
-
-void freeZip(Zip *zip) {
-  aui8_free(zip->iord);
-  aui8_free(zip->candidates);
-  free(zip);
-}
-
-uint8_t getMTabIndexAtPos(Zip *zip) {
-  return *aui8_at(zip->iord, zip->pos);
-}
-
-uint8_t getMTabIndexAtLast(Zip *zip) {
-  return *aui8_at(zip->iord, zip->lastEntry);
-}
-
-bool isOverEnd(Zip *zip) {
-  return zip->pos >= (zip->n - 1) * (zip->n - 1);
-}
-
-bool isOverStart(Zip *zip) {
-  return zip->pos < 0;
-}
-
-bool doStep(MTab *mtab, Zip* zip) {
-  if(isOverEnd(zip)) zip->pos--;
-  if(!upEntry(mtab, zip)) return 0;
-  if(!isAsocIncmplIncrm(mtab, zip)) {
-    if(zip->pos > zip->lastEntry) {
-      zip->pos--;
-    }
-  }
-  return 1;
-}
-
-bool upEntry(MTab *mtab, Zip *zip) {
-  uint8_t n = zip->n;
-  uint32_t index = getMTabIndexAtPos(zip);
-  uint8_t r = getRowIndex(n, index);
-  uint8_t c = getColIndex(n, index);
-  uint8_t currentEle = *aui8_at(mtab, index);
-
-  // ele = max ele
-  if(currentEle == n - 1) {
-    *aui8_at(mtab, index) = 0xff;
-    // Are we at the beginning?
-    if(zip->pos == 0) {
-      return 0;
-    } else {
-      zip->pos--;
-      zip->lastEntry--;
-      return 1;
-    }
-  }
-  uint8_t offset;
-  if(currentEle == 0xff) {
-    offset = 0;
-  } else {
-    offset = currentEle + 1; // in [1, n - 1]
-  }
-  uint8_t ele;
-  uint32_t i;
-  for(i = 0; i < n - offset; i++) {
-    *aui8_at(zip->candidates, i) = i + offset;
-  }
-  // check rows
-  for(i = r * n; i < (r + 1) * n; i++) {
-    ele = *aui8_at(mtab, i);
-    if(ele != 0xff && (currentEle == 0xff || ele > currentEle)) {
-      *aui8_at(zip->candidates, ele - offset) = 0xff;
-    }
-  }
-  // check cols
-  for(i = c; i < n * (n - 1) + c; i+=n) {
-    ele = *aui8_at(mtab, i);
-    if(ele != 0xff && (currentEle == 0xff || ele > currentEle)) {
-      *aui8_at(zip->candidates, ele - offset) = 0xff;
-    }
-  }
-  //printArray_uint8(pstring, zip->candidates);
-  uint8_t nextB = 0xff;
-  for(i = 0; i < n - offset; i++) {
-    ele = *aui8_at(zip->candidates, i);
-    if(ele != 0xff) {
-      nextB = ele;
-      break;
-    }
-  }
-  if(nextB == 0xff) {
-    *aui8_at(mtab, index) = 0xff;
-    zip->pos--;
-    if(currentEle != 0xff) zip->lastEntry--;
-  } else {
-    *aui8_at(mtab, index) = nextB;
-    zip->pos++;
-    if(currentEle == 0xff) zip->lastEntry++;
-  }
-  return 1;
-}
-
-
-bool isAsocIncmplNaive(MTab *mtab, Zip* zip) {
-  uint8_t a, b, c, ab, ab_c, bc, a_bc;
-  uint8_t n = zip->n;
-
-  for(a = 0; a < n; a++) {
-    for(b = 0; b < n; b++) {
-      for(c = 0; c < n; c++) {
-	ab = *aui8_at(mtab, get2DIndex(n, a, b));
-	if(ab == 0xff) continue;
-	bc = *aui8_at(mtab, get2DIndex(n, b, c));
-	if(bc == 0xff) continue;
-	ab_c = *aui8_at(mtab, get2DIndex(n, ab, c));
-	if(ab_c == 0xff) continue;
-	a_bc = *aui8_at(mtab, get2DIndex(n, a, bc));
-	if(a_bc == 0xff) continue;
-	if(ab_c != a_bc) return 0;
-      }
-    }
-  }
-  return 1;
-}
-
-bool isAsocIncmplIncrm(MTab *mtab, Zip* zip) {
-  uint8_t n = zip->n;
-  uint32_t index = getMTabIndexAtLast(zip);
-  uint8_t a = getRowIndex(n, index);
-  uint8_t b = getColIndex(n, index);
-  uint8_t ab = *aui8_at(mtab, index);
-
-  // check ab_c = a_bc
-  uint8_t c, bc, ab_c, a_bc;
-  for(c = 0; c < n; c++) {
-    bc = *aui8_at(mtab, get2DIndex(n, b, c));
-    if(bc == 0xff) continue;
-    a_bc = *aui8_at(mtab, get2DIndex(n, a, bc));
-    if(a_bc == 0xff) continue;
-    ab_c = *aui8_at(mtab, get2DIndex(n, ab, c));
-    if(ab_c == 0xff) continue;
-    if(ab_c != a_bc) return 0;
-  }
-
-  // check c_ab = ca_b
-  uint8_t ca, c_ab, ca_b;
-  for(c = 0; c < n; c++) {
-    ca = *aui8_at(mtab, get2DIndex(n, c, a));
-    if(ca == 0xff) continue;
-    ca_b = *aui8_at(mtab, get2DIndex(n, ca, b));
-    if(ca_b == 0xff) continue;
-    c_ab = *aui8_at(mtab, get2DIndex(n, c, ab));
-    if(c_ab == 0xff) continue;
-    if(ca_b != c_ab) return 0;
-  }
-
-  // go through preimages of a to check (x)(y b) = [(x y) b = ab]
-  uint8_t ele, x, y, yb, x_yb;
-  uint32_t i;
-  for(i = 0; i < mtab->size; i++) {
-    ele = *aui8_at(mtab, i);
-    if(ele == a) {
-      x = getRowIndex(n, i);
-      y = getColIndex(n, i);
-      yb = *aui8_at(mtab, get2DIndex(n, y, b));
-      if(yb == 0xff) continue;
-      x_yb = *aui8_at(mtab, get2DIndex(n, x, yb));
-      if(x_yb == 0xff) continue;
-      if(x_yb != ab) return 0;
-    }
-  }
-
-  // go through preimages of b to check (a x) y = [a (x y) = ab
-  uint8_t ax, ax_y;
-  for(i = 0; i < mtab->size; i++) {
-    ele = *aui8_at(mtab, i);
-    if(ele == b) {
-      x = getRowIndex(n, i);
-      y = getColIndex(n, i);
-      ax = *aui8_at(mtab, get2DIndex(n, a, x));
-      if(ax == 0xff) continue;
-      ax_y = *aui8_at(mtab, get2DIndex(n, ax, y));
-      if(ax_y == 0xff) continue;
-      if(ax_y != ab) return 0;
-    }
-  }
-  return 1;
-}
-
-void initIOrd(Zip *zip) {
-  uint8_t pos = 0;
-  uint8_t val = 0;
-  uint8_t n = zip->n;
-  uint8_t i, r, d;
-
-  for(i = 1; i < n; i++) {
-    val = i * n + 1;
-    *aui8_at(zip->iord, pos) = val;
-    pos++;
-    for(r = 0; r < i - 1; r++) {
-      val++;
-      *aui8_at(zip->iord, pos) = val;
-      pos++;
-    }
-    for(d = 0; d < i - 1; d++) {
-      val -= n;
-      *aui8_at(zip->iord, pos) = val;
-      pos++;
-    }
-  }
-}
-
-void initMTab(MTab* mtab, Zip *zip, uint8_t init) {
-  uint8_t i;
-  uint8_t j;
-  uint8_t n = zip->n;
-  for(i = 0; i < n; i++) {
-    for(j = 0; j < n; j++) {
-      if(i == 0) {
-	*aui8_at(mtab, j) = j;
-      } else if(j == 0) {
-	*aui8_at(mtab, i * n) = i;
-      } else {
-	*aui8_at(mtab, i * n + j) = 0xff;
-      }
-    }
-  }
-  *aui8_at(mtab, n + 1) = init;
-}
-
-void printZip(Zip *zip) {
-  printf("Zip = [ n=%u p=%u l=%u ]\n", zip->n, zip->pos, zip->lastEntry);
-}
-
-bool isComplete(MTab *mtab, uint8_t n) {
-  return *aui8_at(mtab, n * 2 - 1) != 0xff;
-}

+ 0 - 40
src/gen/asocgen.h

@@ -1,40 +0,0 @@
-#ifndef ASOCGEN
-#define ASOCGEN
-
-#include <stdint.h>
-#include "../common/common_includes.h"
-
-
-typedef Array_uint8 MTab;
-
-struct Zip {
-  uint8_t n;
-  uint32_t pos;
-  uint32_t lastEntry;
-  Array_uint8 *iord;
-  Array_uint8 *candidates;
-};
-typedef struct Zip Zip;
-
-Zip *allocZip(uint8_t n);
-void freeZip(Zip *zip);
-
-uint8_t getMTabIndexAtPos(Zip *zip);
-uint8_t getMTabIndexAtLast(Zip *zip);
-bool isOverEnd(Zip *zip);
-bool isOverStart(Zip *zip);
-
-void initIOrd(Zip *zip);
-void initMTab(MTab* mtab, Zip *zip, uint8_t init);
-
-bool upEntry(MTab *mtab, Zip* zip);
-bool doStep(MTab *mtab, Zip* zip);
-
-bool isAsocIncmplNaive(MTab *mtab, Zip* zip);
-bool isAsocIncmplIncrm(MTab *mtab, Zip* zip);
-
-void printZip(Zip *zip);
-
-bool isComplete(MTab *mtab, uint8_t n);
-
-#endif

+ 230 - 159
src/group/group.c

@@ -1,175 +1,206 @@
 #include "group.h"
 
+#include <elfc_math.h>
+
 #include <stdlib.h>
 #include <stdio.h>
-#include "group_hom.h"
 
 
-Group *group_alloc(uint16_t order, bool indexed) {
+// ---------------------------------------------------------------------------
+// Management
+// ---------------------------------------------------------------------------
+
+Group *group_alloc(u16 order, bool indexed)
+{
   Group *group = malloc(sizeof(Group));
   group->indexed = indexed;
-  group->set = aui16_alloc(order);
-  group->gtab = aui16_alloc(order * order);
+  group->set = vecu16_alloc(order);
+  group->gtab = vecu16_alloc(order * order);
   return group;
 }
 
-void group_free(Group *group) {
-  aui16_free(group->gtab);
-  aui16_free(group->set);
+void group_free(Group *group)
+{
+  vecu16_free(group->gtab);
+  vecu16_free(group->set);
   free(group);
 }
 
-bool group_checkIndexed(Group *group) {
-  uint32_t i;
-  for(i = 0; i < group_order(group); i++) {
-    if(*aui16_at(group->set, i) != i) {
+bool group_checkIndexed(Group *group)
+{
+  for(i32 i = 0; i < group_order(group); i++) {
+    if(*vecu16_at(group->set, i) != i) {
       return 0;
     }
   }
   return 1;
 }
 
-Group *group_getIndexedCopy_alloc(Group *group) {
-  Map_uint16 *map = mapui16_alloc(group_order(group), group->indexed);
-  aui16_copyInto(map->domain, group->set);
-  aui16_setToRange(map->codomain, 0, map->codomain->size, 0);
+Group *group_getIndexedCopy_alloc(Group *group)
+{
+  Mapu16 *map = mapu16_alloc(group_order(group), group->indexed);
+  vecu16_copyInto(map->domain, group->set);
+  vecu16_setToRange(map->codomain, 0, map->codomain->size, 0);
   Group *copy = group_getRenamedCopy_alloc(group, map);
-  mapui16_free(map);
+  mapu16_free(map);
   return copy;
 }
 
-Group *group_getRenamedCopy_alloc(Group *group, Map_uint16 *map) {
+Group *group_getRenamedCopy_alloc(Group *group, Mapu16 *map)
+{
   Group *copy = group_alloc(group_order(group), 0);
-  mapui16_mapArray(map, group->set, copy->set);
-  mapui16_mapArray(map, group->gtab, copy->gtab);
+  mapu16_mapEleVec(map, group->set, copy->set);
+  mapu16_mapEleVec(map, group->gtab, copy->gtab);
   copy->indexed = group_checkIndexed(copy);
   return copy;
 }
 
-// --------------------------------------------------------------------------
 
-bool group_isCommutative(Group *group) {
-  uint32_t i, j;
-  uint16_t n = group_order(group);
-  for(i = 0; i < n; i++) {
-    for(j = 0; j < n; j++) {
-      if(gopi(group, i, j) != gopi(group, j, i)) return 0;
+// ---------------------------------------------------------------------------
+// Information
+// ---------------------------------------------------------------------------
+
+bool group_isCommutative(Group *group)
+{
+  u16 n = group_order(group);
+  for(i32 i = 0; i < n; i++) {
+    for(i32 j = 0; j < n; j++) {
+      if(group_opi(group, i, j) != group_opi(group, j, i)) {
+        return 0;
+      }
     }
   }
   return 1;
 }
 
-bool group_isCyclic(Group *group) {
-  uint32_t i;
-  uint16_t n = group_order(group);
-  for(i = 0; i < n; i++) {
-    if(group_elementOrder(group, *aui16_at(group->set, i)) == n) return 1;
+bool group_isCyclic(Group *group)
+{
+  u16 n = group_order(group);
+  for(i32 i = 0; i < n; i++) {
+    if(group_elementOrder(group, *vecu16_at(group->set, i)) == n) {
+      return 1;
+    }
   }
   return 0;
 }
 
-uint16_t group_elementOrder(Group *group, uint16_t ele) {
-  uint16_t r = ele;
-  uint16_t ord = 1;
-  while(r != 0) {
-    r = gop(group, r, ele);
+u16 group_elementOrder(Group *group, u16 ele)
+{
+  u16 r = ele;
+  u16 ord = 1;
+  u16 neutral = group_neutral(group);
+  while(r != neutral) {
+    //printf("r = %i\n", r);
+    r = group_op(group, r, ele);
     ord++;
   }
   return ord;
 }
 
-uint16_t group_elementOrderi(Group *group, uint16_t ind) {
-  uint16_t r = ind;
-  uint16_t ord = 1;
-  while(r != 0) {
-    r = gopi(group, r, ind);
+u16 group_elementOrderi(Group *group, u16 ind)
+{
+  u16 r = ind;
+  u16 ord = 1;
+  u16 neutralInd = group_neutrali(group);
+  while(r != neutralInd) {
+    r = group_opi(group, r, ind);
     ord++;
   }
   return ord;
 }
 
-Map_uint16 *group_orderDist_alloc(Group *group) {
-  uint32_t n = group_order(group);
-  Array_uint16 *primeFac = getFactors_alloc(n);
-  Array_uint16 *orderCounts = aui16_alloc(primeFac->size);
-  aui16_fill(orderCounts, 0);
-  uint32_t i, orderi;
-  for(i = 0; i < n; i++) {
+Mapu16 *group_orderDist_alloc(Group *group)
+{
+  u32 n = group_order(group);
+  Vecu16 *primeFac = math_getFactors_alloc(n);
+  Vecu16 *orderCounts = vecu16_alloc(primeFac->size);
+  vecu16_fill(orderCounts, 0);
+  u32 orderi;
+  u32 ind = -1;
+  for(i32 i = 0; i < n; i++) {
     orderi = group_elementOrderi(group, i);
-    (*aui16_at(orderCounts, aui16_indexOf(primeFac, orderi)))++;
+    if(vecu16_indexOf(primeFac, orderi, &ind, 0)) {
+      (*vecu16_at(orderCounts, ind))++;
+    }
   }
-  Map_uint16 *map = mapui16_alloc_ref(primeFac->size, 0,primeFac,orderCounts);
+  // ref alloc is okay since the vectors alloc'd are exactly dom / codom
+  Mapu16 *map = mapu16_alloc_ref(primeFac, orderCounts, 0);
   return map;
 }
 
-uint16_t group_neutral(Group *group) {
-  return *aui16_at(group->set, group_neutrali(group));
+u16 group_neutral(Group *group)
+{
+  return *vecu16_at(group->set, group_neutrali(group));
 }
 
-uint16_t group_neutrali(Group *group) {
-  uint32_t i;
-  uint16_t neutralInd = 0xffff;
-  for(i = 0; i < group_order(group); i++) {
-    if(gopi(group, i, 0) == 0) {
-      neutralInd = i;
+u16 group_neutrali(Group *group)
+{
+  for(i32 i = 0; i < group_order(group); i++) {
+    if(group_opi(group, i, 0) == 0) {
+      return i;
       break;
     }
   }
-  return neutralInd;
+  return 0xffff; // error value
 }
 
 
-uint16_t group_invi(Group *group, uint16_t ind) {
-  uint32_t n = group_order(group);
-  uint16_t neuInd = group_neutrali(group);
-  uint32_t i;
-  for(i = 0; i < n; i++) {
-    if(gopi(group, ind, i) == neuInd) {
+u16 group_invi(Group *group, u16 ind) {
+  u32 n = group_order(group);
+  u16 neuInd = group_neutrali(group);
+  for(i32 i = 0; i < n; i++) {
+    if(group_opi(group, ind, i) == neuInd) {
       return i;
     }
   }
-  return 0xffff;
+  return 0xffff; // might be misleading value. Should produce error value
 }
 
-uint16_t group_inv(Group *group, uint16_t ele) {
-  uint16_t ind = ele;
+u16 group_inv(Group *group, u16 ele) {
+  u32 ind = ele;
   if(!group->indexed) {
-    ind = aui16_indexOf(group->set, ele);
+    vecu16_indexOf(group->set, ele, &ind, 0);
   }
-  return *aui16_at(group->set, group_invi(group, ind));
+  return *vecu16_at(group->set, group_invi(group, ind));
 }
 
-// --------------------------------------------------------------------------
 
-uint16_t group_conjEle(Group* group, uint16_t toConj, uint16_t a) {
-  return gop(group, a, gop(group, toConj, group_inv(group, a)));
+// ---------------------------------------------------------------------------
+// Subgroup related
+// ---------------------------------------------------------------------------
+
+u16 group_conjEle(Group* group, u16 toConj, u16 a)
+{
+  return group_op(group, a, group_op(group, toConj, group_inv(group, a)));
 }
 
-uint16_t group_conjElei(Group *group, uint16_t toConj, uint16_t a) {
-  return gopi(group, a, gopi(group, toConj, group_invi(group, a)));
+u16 group_conjElei(Group *group, u16 toConj, u16 a)
+{
+  return group_opi(group, a, group_opi(group, toConj, group_invi(group, a)));
 }
 
-Array_uint16 *group_leftCoset_alloc(Group *group, Group *subgroup,
-                                    uint16_t ele) {
+/*
+Vecu16 *group_leftCoset_alloc(Group *group, Group *subgroup, u16 ele)
+{
   return 0;
 }
 
-Array_uint16 *group_rightCoset_alloc(Group *group, Group *subgroup,
-                                     uint16_t ele) {
+Vecu16 *group_rightCoset_alloc(Group *group, Group *subgroup, u16 ele) {
   return 0;
 }
+*/
 
-bool group_isSubgroup(Group *group, Group *subgroup) {
-  if(!aui16_isSubset(subgroup->set, group->set)) {
+bool group_isSubgroup(Group *group, Group *subgroup)
+{
+  if(!vecu16_isSubset(subgroup->set, group->set)) {
     return 0;
   }
-  uint32_t i, j;
-  uint16_t a, b;
-  for(i = 0; i < group_order(subgroup); i++) {
-    a = *aui16_at(subgroup->set, i);
-    for(j = 0; j < group_order(subgroup); j++) {
-      b = *aui16_at(subgroup->set, j);
-      if(gop(group, a, b) != gop(subgroup, a, b)) {
+  u16 a, b;
+  for(i32 i = 0; i < group_order(subgroup); i++) {
+    a = *vecu16_at(subgroup->set, i);
+    for(i32 j = 0; j < group_order(subgroup); j++) {
+      b = *vecu16_at(subgroup->set, j);
+      if(group_op(group, a, b) != group_op(subgroup, a, b)) {
         return 0;
       }
     }
@@ -177,130 +208,170 @@ bool group_isSubgroup(Group *group, Group *subgroup) {
   return 1;
 }
 
-bool group_isNormalSubgroup(Group *group, Group *subgroup) {
-  Array_uint16 *conjSet = aui16_alloc(group_order(subgroup));
-  uint32_t i, j;
-  for(i = 0; i < group_order(group); i++) {
-    for(j = 0; j < group_order(subgroup); j++) {
-      *aui16_at(conjSet, j) = *aui16_at(group->set,
-                                        group_conjElei(group, j, i));
+bool group_isNormalSubgroup(Group *group, Group *subgroup)
+{
+  Vecu16 *conjSet = vecu16_alloc(group_order(subgroup));
+  bool isNormal = 1;
+  for(i32 i = 0; i < group_order(group); i++) {
+    // for index i calculate the set of conj elements jij^-1 and check eqlity
+    for(i32 j = 0; j < group_order(subgroup); j++) {
+      *vecu16_at(conjSet, j) = *vecu16_at(group->set,
+                                          group_conjElei(group, j, i));
     }
-    if(!aui16_areEqualSets(conjSet, subgroup->set)) {
-      return 0;
+    isNormal = isNormal && vecu16_areEqualSets(conjSet, subgroup->set);
+    if(!isNormal) {
+      break;
     }
   }
-  aui16_free(conjSet);
-  return 1;
+  vecu16_free(conjSet);
+  return isNormal;
 }
 
-// --------------------------------------------------------------------------
 
-bool group_isValid(Group *group) {
-  return group_hasValidOp(group) &&
-    group_isAsoc(group) &&
-    group_hasNeutral(group) &&
-    group_hasInvs(group);
+// ---------------------------------------------------------------------------
+// Validation
+// ---------------------------------------------------------------------------
+
+bool group_isValid(Group *group)
+{
+  return group_hasValidSet(group) &&
+         group_hasValidOp(group) &&
+         group_isAsoc(group) &&
+         group_hasNeutral(group) &&
+         group_hasInvs(group);
 }
 
-bool group_hasValidOp(Group *group) {
-  uint32_t n = group_order(group);
-  Array_uint16 *row = aui16_copy(group->set);
-  Array_uint16 *col = aui16_copy(group->set);
-  uint32_t i, j;
-  for(i = 0; i < n; i++) {
-    for(j = 0; j < n; j++) {
-      *aui16_at(row, gopi(group, i, j)) = 0xffff;
-      *aui16_at(col, gopi(group, j, i)) = 0xffff;
-    }
-    for(j = 0; j < n; j++) {
-      if(*aui16_at(row, j) != 0xffff || *aui16_at(col, j) != 0xffff) {
-        aui16_free(row);
-        aui16_free(col);
+bool group_hasValidSet(Group *group)
+{
+  // if indexed=1 then check if really indexed
+  if(group->indexed) {
+    for(i32 i = 0; i < group->set->size; i++) {
+      if(*vecu16_at(group->set, i) != i) {
         return 0;
       }
-      *aui16_at(row, j) = 0; // just not 0xffff
-      *aui16_at(col, j) = 0; // just not 0xffff
     }
   }
-  aui16_free(row);
-  aui16_free(col);
-  return 1;
+  // check that no duplicate entries and no 0xffff entries
+  return !vecu16_hasDuplicates(group->set) &&
+         !vecu16_contains(group->set, 0xffff, 0);
 }
 
-bool group_isAsoc(Group *group) {
-  uint16_t a, b, c, ab, ab_c, bc, a_bc;
-  uint32_t n = group_order(group);
-  for(a = 0; a < n; a++) {
-    for(b = 0; b < n; b++) {
-      for(c = 0; c < n; c++) {
-	ab = gopi(group, a, b);
-	bc = gopi(group, b, c);
-        ab_c = gopi(group, ab, c);
-	a_bc = gopi(group, a, bc);
-	if(ab_c != a_bc) return 0;
+bool group_hasValidOp(Group *group)
+{
+  u32 n = group_order(group);
+  // masks for row, col to check that opi(i, j), opi(j, i) attains all vals
+  Vecu16 *row = vecu16_copy(group->set); // vec with no element 0xffff
+  Vecu16 *col = vecu16_copy(group->set); // ^
+  bool isValid = 1;
+  for(i32 i = 0; i < n; i++) {
+    for(i32 j = 0; j < n; j++) {
+      *vecu16_at(row, group_opi(group, i, j)) = 0xffff;
+      *vecu16_at(col, group_opi(group, j, i)) = 0xffff;
+    }
+    for(i32 j = 0; j < n; j++) {
+      // check that only 0xffff entries exist
+      isValid = isValid &&
+                *vecu16_at(row, j) == 0xffff &&
+                *vecu16_at(col, j) == 0xffff;
+    }
+    if(!isValid) {
+      break;
+    }
+    vecu16_fill(row, 0);
+    vecu16_fill(col, 0);
+  }
+  vecu16_free(row);
+  vecu16_free(col);
+  return isValid;
+}
+
+bool group_isAsoc(Group *group)
+{
+  u16 ab, ab_c, bc, a_bc;
+  u32 n = group_order(group);
+  for(u16 a = 0; a < n; a++) {
+    for(u16 b = 0; b < n; b++) {
+      for(u16 c = 0; c < n; c++) {
+        ab = group_opi(group, a, b);
+        bc = group_opi(group, b, c);
+        ab_c = group_opi(group, ab, c);
+        a_bc = group_opi(group, a, bc);
+        if(ab_c != a_bc) {
+          return 0;
+        }
       }
     }
   }
   return 1;
 }
 
-bool group_hasNeutral(Group *group) {
-  uint32_t n = group_order(group);
-  uint32_t neutralInd = group_neutrali(group);
+bool group_hasNeutral(Group *group)
+{
+  u32 n = group_order(group);
+  u32 neutralInd = group_neutrali(group);
   if(neutralInd >= n) {
     return 0;
   }
   // Check if neutral is indeed neutral (does not check uniqueness)
-  uint32_t i;
-  for(i = 0; i < n; i++) {
-    if(gopi(group, i, neutralInd) != i || gopi(group, neutralInd, i) != i) {
+  for(i32 i = 0; i < n; i++) {
+    if(group_opi(group, i, neutralInd) != i ||
+       group_opi(group, neutralInd, i) != i) {
       return 0;
     }
   }
   return 1;
 }
 
-bool group_hasInvs(Group *group) {
-  uint32_t n = group_order(group);
-  uint16_t neuInd = group_neutrali(group);
-  uint32_t i, invInd;
-  for(i = 0; i < n; i++) {
+bool group_hasInvs(Group *group)
+{
+  u32 n = group_order(group);
+  u16 neuInd = group_neutrali(group);
+  u32 invInd;
+  for(i32 i = 0; i < n; i++) {
     invInd = group_invi(group, i);
     if(invInd >= n) {
       return 0;
     }
-    if(gopi(group, invInd, i) != neuInd || gopi(group, i, invInd) != neuInd) {
+    if(group_opi(group, invInd, i) != neuInd ||
+       group_opi(group, i, invInd) != neuInd) {
       return 0;
     }
   }
   return 1;
 }
 
-// --------------------------------------------------------------------------
 
+// ---------------------------------------------------------------------------
+// Print
+// ---------------------------------------------------------------------------
+
+/*
 void group_print(Group *group) {
-  uint32_t n = group_order(group);
+  u32 n = group_order(group);
   char *pstring = malloc(n * n * 6 + n * 6 * 2 + 100); // just a guess
   char *valid;
   if(group_isValid(group)) valid = "valid";
   else valid = "INVALID";
   printf("Group of order %u (%s)\n", n, valid);
-  aui16_printSquare(group->gtab, 2);
+  vecu16_printSquare(group->gtab, 2);
   free(pstring);
 }
+*/
 
 void group_printSummary(Group *group) {
-  uint32_t n = group_order(group);
+  u32 n = group_order(group);
   printf("Summary of group candidate of order %u\n", n);
-  printf("  (*) hasGroupOp %u\n", group_hasValidOp(group));
-  printf("  (*) isAssoc    %u\n", group_isAsoc(group));
-  printf("  (*) hasNeutral %u\n", group_hasNeutral(group));
-  printf("  (*) hasInvs    %u\n\n", group_hasInvs(group));
+  printf("  (*) isIndexed   %u\n", group->indexed);
+  printf("  (*) hasValidSet %u\n", group_hasValidSet(group));
+  printf("  (*) hasGroupOp  %u\n", group_hasValidOp(group));
+  printf("  (*) isAssoc     %u\n", group_isAsoc(group));
+  printf("  (*) hasNeutral  %u\n", group_hasNeutral(group));
+  printf("  (*) hasInvs     %u\n\n", group_hasInvs(group));
   printf("  (*) neutral Element %u\n", group_neutral(group));
   printf("  (*) isCyclic        %u\n", group_isCyclic(group));
   printf("  (*) isCommutative   %u\n\n", group_isCommutative(group));
-  Map_uint16 *orderMap = group_orderDist_alloc(group);
-  printf("  (*) order distribution:\n");
-  mapui16_printToWidth(orderMap, 80, 2);
-  mapui16_free(orderMap);
+  //Map_uint16 *orderMap = group_orderDist_alloc(group);
+  //printf("  (*) order distribution:\n");
+  //mapui16_printToWidth(orderMap, 80, 2);
+  //mapui16_free(orderMap);
 }

+ 57 - 42
src/group/group.h

@@ -1,107 +1,122 @@
 #ifndef GROUP
 #define GROUP
 
-#include "../common/common_includes.h"
+#include <elfc_common.h>
+#include <elfc_vecu16.h>
+#include <elfc_mapu16.h>
 
-/*
-  Represents a group. If indexed is 1, then set must be id = { 0, 1, ..., n }
-*/
 
+/*
+ * Represents a group. If indexed is 1, then set must be id = { 0, 1, ..., n }
+ */
 struct Group {
   bool indexed;
-  Array_uint16 *set;
-  Array_uint16 *gtab;
+  Vecu16 *set;
+  Vecu16 *gtab;
 };
 typedef struct Group Group;
 
 
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 // Management
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 
-Group *group_alloc(uint16_t order, bool indexed);
+Group *group_alloc(u16 order, bool indexed);
 void group_free(Group *group);
 
 bool group_checkIndexed(Group *group);
 
 Group *group_getIndexedCopy_alloc(Group *group);
-Group *group_getRenamedCopy_alloc(Group *group, Map_uint16 *map);
+Group *group_getRenamedCopy_alloc(Group *group, Mapu16 *map);
 
 
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 // Information
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 
 bool group_isCommutative(Group *group);
 bool group_isCyclic(Group *group);
 
-uint16_t group_elementOrder(Group *group, uint16_t ele);
-uint16_t group_elementOrderi(Group *group, uint16_t ind);
-Map_uint16 *group_orderDist_alloc(Group *group);
+u16 group_elementOrder(Group *group, u16 ele);
+u16 group_elementOrderi(Group *group, u16 ind);
+Mapu16 *group_orderDist_alloc(Group *group);
 
-uint16_t group_neutral(Group *group);
-uint16_t group_neutrali(Group *group);
+u16 group_neutral(Group *group);
+u16 group_neutrali(Group *group);
 
-uint16_t group_inv(Group *group, uint16_t ele);
-uint16_t group_invi(Group *group, uint16_t ind);
+u16 group_inv(Group *group, u16 ele);
+u16 group_invi(Group *group, u16 ind);
 
 
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 // Subgroup related
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 
-uint16_t group_conjEle(Group *group, uint16_t toConj, uint16_t a);
-uint16_t group_conjElei(Group *group, uint16_t toConj, uint16_t a);
+u16 group_conjEle(Group *group, u16 toConj, u16 a);
+u16 group_conjElei(Group *group, u16 toConj, u16 a);
 
-Array_uint16 *group_leftCoset_alloc(Group *group, Group *subgroup,
-                                    uint16_t ele);
-Array_uint16 *group_rightCoset_alloc(Group *group, Group *subgroup,
-                                     uint16_t ele);
+Vecu16 *group_leftCoset_alloc(Group *group, Group *subgroup, u16 ele);
+Vecu16 *group_rightCoset_alloc(Group *group, Group *subgroup, u16 ele);
 
 bool group_isSubgroup(Group *group, Group *subgroup);
 bool group_isNormalSubgroup(Group *group, Group *subgroup);
 
-// --------------------------------------------------------------------------
+
+// ---------------------------------------------------------------------------
 // Validation
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 
 bool group_isValid(Group *group);
+
+bool group_hasValidSet(Group *group);
 bool group_hasValidOp(Group *group);
 bool group_isAsoc(Group *group);
 bool group_hasNeutral(Group *group);
 bool group_hasInvs(Group *group);
 
 
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 // Print
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 
 void group_printSummary(Group *group);
-void group_print(Group *group);
+//void group_print(Group *group);
 
 
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 // Inline Functions
-// --------------------------------------------------------------------------
+// ---------------------------------------------------------------------------
 
-inline uint16_t group_order(Group *group) {
+inline u16 group_order(Group *group)
+{
   return group->set->size;
 }
 
 // ele * ele -> ele
-inline uint16_t gop(Group *group, uint16_t i, uint16_t j) {
+inline u16 group_op(Group *group, u16 i, u16 j)
+{
+  u32 indi = i;
+  u32 indj = j;
   if(!group->indexed) {
-    i = aui16_indexOf(group->set, i);
-    j = aui16_indexOf(group->set, j);
+    vecu16_indexOf(group->set, i, &indi, 0);
+    vecu16_indexOf(group->set, j, &indj, 0);
   }
-  return *aui16_at(group->gtab, get2DIndex(group_order(group), i, j));
+  return *vecu16_at(group->gtab, get2DIndex(group_order(group), indi, indj));
 }
 
 // index * index -> index
-inline uint16_t gopi(Group *group, uint16_t i, uint16_t j) {
-  uint16_t ele = *aui16_at(group->gtab, get2DIndex(group_order(group), i, j));
+inline u16 group_opi(Group *group, u16 i, u16 j)
+{
+  u16 ele = *vecu16_at(group->gtab, get2DIndex(group_order(group), i, j));
   if(!group->indexed) {
-    return aui16_indexOf(group->set, ele);
+    u32 ind = -1;
+    bool ok = vecu16_indexOf(group->set, ele, &ind, 0);
+#ifdef BOUNDS_CHECK
+    if(!ok) {
+      // TODO improve this to standardized error-out
+    }
+#endif
+    return ind;
   }
   return ele;
 }

+ 112 - 81
src/group/group_common.c

@@ -1,74 +1,98 @@
 #include "group_common.h"
 
+#include <elfc_math.h>
+#include <elfc_vecptr.h>
+#include <elfc_perm.h>
+
 #include <math.h>
+#include <stdlib.h>