[BACK]Return to cmolen.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / ox_toolkit

Annotation of OpenXM/src/ox_toolkit/cmolen.c, Revision 1.2

1.1       ohara       1: /* -*- mode: C; coding: euc-japan -*- */
1.2     ! ohara       2: /* $OpenXM: OpenXM/src/ox_toolkit/cmolen.c,v 1.1 2000/10/10 05:23:20 ohara Exp $ */
1.1       ohara       3:
                      4: /* This module is needed by bconv.c */
                      5:
                      6: /*
                      7: The cmolen_cmo() function returns the length of the binary encoded
                      8: object for a given cmo.
                      9: cmolen_cmo_XXX() functions return the length of the binary encoded cmo
                     10: except its tag.
                     11: */
                     12:
                     13: #include "ox_toolkit.h"
                     14:
                     15: static int          cmolen_cmo_int32(cmo_int32* c);
                     16: static int          cmolen_cmo_list(cmo_list* c);
                     17: static int          cmolen_cmo_mathcap(cmo_mathcap* c);
                     18: static int          cmolen_cmo_null(cmo_null* c);
                     19: static int          cmolen_cmo_string(cmo_string* c);
1.2     ! ohara      20: #if defined(WITH_GMP)
1.1       ohara      21: static int          cmolen_cmo_zz(cmo_zz* c);
1.2     ! ohara      22: #endif /* WITH_GMP */
1.1       ohara      23: static int          cmolen_cmo_monomial32(cmo_monomial32* c);
                     24:
                     25: __inline__
                     26: static int cmolen_cmo_null(cmo_null* c)
                     27: {
                     28:     return 0;
                     29: }
                     30:
                     31: static int cmolen_cmo_int32(cmo_int32* c)
                     32: {
                     33:     return sizeof(int);
                     34: }
                     35:
                     36: static int cmolen_cmo_string(cmo_string* c)
                     37: {
                     38:     return sizeof(int)+strlen(c->s);
                     39: }
                     40:
                     41: static int cmolen_cmo_mathcap(cmo_mathcap* c)
                     42: {
                     43:     return cmolen_cmo(c->ob);
                     44: }
                     45:
                     46: static int cmolen_cmo_list(cmo_list* c)
                     47: {
                     48:     int size = sizeof(int);
                     49:     cell* cp;
                     50:     for(cp = list_first(c); !list_endof(c, cp); cp = list_next(cp)) {
                     51:         size += cmolen_cmo(cp->cmo);
                     52:     }
                     53:     return size;
                     54: }
                     55:
                     56: static int cmolen_cmo_monomial32(cmo_monomial32* c)
                     57: {
                     58:     int len = (c->length + 1)*sizeof(int);
                     59:     return len + cmolen_cmo(c->coef);
                     60: }
                     61:
1.2     ! ohara      62: #if defined(WITH_GMP)
1.1       ohara      63: static int cmolen_cmo_zz(cmo_zz* c)
                     64: {
                     65:     int len = abs(c->mpz->_mp_size);
                     66:     return sizeof(int) + len*sizeof(int);
                     67: }
1.2     ! ohara      68: #endif /* WITH_GMP */
1.1       ohara      69:
                     70: static int cmolen_cmo_distributed_polynomial(cmo_distributed_polynomial* c)
                     71: {
                     72:     return cmolen_cmo_list((cmo_list *)c) + cmolen_cmo(c->ringdef);
                     73: }
                     74:
                     75: /* a function calculating the length of the byte stream of a given CMO.  */
                     76: int cmolen_cmo(cmo* c)
                     77: {
                     78:     int size = sizeof(int);
                     79:
                     80:     switch(c->tag) {
                     81:     case CMO_NULL:
                     82:     case CMO_ZERO:
                     83:     case CMO_DMS_GENERIC:
                     84:         size += cmolen_cmo_null(c);
                     85:         break;
                     86:     case CMO_INT32:
                     87:         size += cmolen_cmo_int32((cmo_int32 *)c);
                     88:         break;
                     89:     case CMO_STRING:
                     90:         size += cmolen_cmo_string((cmo_string *)c);
                     91:         break;
                     92:     case CMO_MATHCAP:
                     93:     case CMO_RING_BY_NAME:
                     94:     case CMO_INDETERMINATE:
                     95:     case CMO_ERROR2:
                     96:         size += cmolen_cmo_mathcap((cmo_mathcap *)c);
                     97:         break;
                     98:     case CMO_LIST:
                     99:         size += cmolen_cmo_list((cmo_list *)c);
                    100:         break;
                    101:     case CMO_MONOMIAL32:
                    102:         size += cmolen_cmo_monomial32((cmo_monomial32 *)c);
                    103:         break;
1.2     ! ohara     104: #if defined(WITH_GMP)
1.1       ohara     105:     case CMO_ZZ:
                    106:         size += cmolen_cmo_zz((cmo_zz *)c);
                    107:         break;
1.2     ! ohara     108: #endif /* WITH_GMP */
1.1       ohara     109:     case CMO_DISTRIBUTED_POLYNOMIAL:
                    110:         size += cmolen_cmo_distributed_polynomial((cmo_distributed_polynomial *)c);
                    111:         break;
                    112:     default:
                    113:     }
                    114:     return size;
                    115: }
                    116:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>