#ifndef LINSYS_H
#define LINSYS_H

#include "linmatrix.h"

#define MAX_SIZE 1000
#define MAX_ETA  5000
#define WELL_CONDITIONED 1e5


typedef enum _MY_BOOL { _FALSE=0, _TRUE} MY_BOOL;

typedef struct _eta_mx{
         int col;
         MY_BOOL swap;
         double  val;
} eta_mx;
typedef struct _linsys{
        linmx* extmx;
        double* lu;
	int * bases;
	int * perm;
        int    num_updates;
        int    num_eta;
        eta_mx  Q[MAX_ETA];
	MY_BOOL luvalid;
        MY_BOOL rowscaling;
        MY_BOOL colscaling;
} *linsys,LinSystem;

linsys ls_init(int rows, int cols);	/*create a new linera system*/
linsys ls_init_copy(linsys  ls);	/*copy an existing linear system*/
void	ls_dispose(linsys ls);	/*dispose a linear system*/

int ls_lucrout(double m[],int n, int perm[]);
int ls_solve(linsys ls,double b[]);
int ls_create_lu(linsys ls, int newbase[]);

void ls_scaleHall(linsys ls,int rowscale,int colscale);
void ls_scaleGondzio(linsys ls,int rowscale,int colscale);

int ls_updatelu(linsys ls, int entering,int leaving);

int ls_varinbase(linsys ls,int varno);
int ls_applypermut(linsys,double v[]);
void ls_forwardsub(linsys ls, double b[]);
void ls_backwardsub(linsys ls, double b[]);

double Hallfactor(double v[],int n);
double Gondziofactor(double v[],int n);

#endif