Leptonica  1.77.0
Image processing and image analysis suite
dnabasic.c File Reference
#include <string.h>
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

static l_int32 l_dnaExtendArray (L_DNA *da)
 
static l_int32 l_dnaaExtendArray (L_DNAA *daa)
 
L_DNAl_dnaCreate (l_int32 n)
 
L_DNAl_dnaCreateFromIArray (l_int32 *iarray, l_int32 size)
 
L_DNAl_dnaCreateFromDArray (l_float64 *darray, l_int32 size, l_int32 copyflag)
 
L_DNAl_dnaMakeSequence (l_float64 startval, l_float64 increment, l_int32 size)
 
void l_dnaDestroy (L_DNA **pda)
 
L_DNAl_dnaCopy (L_DNA *da)
 
L_DNAl_dnaClone (L_DNA *da)
 
l_ok l_dnaEmpty (L_DNA *da)
 
l_ok l_dnaAddNumber (L_DNA *da, l_float64 val)
 
l_ok l_dnaInsertNumber (L_DNA *da, l_int32 index, l_float64 val)
 
l_ok l_dnaRemoveNumber (L_DNA *da, l_int32 index)
 
l_ok l_dnaReplaceNumber (L_DNA *da, l_int32 index, l_float64 val)
 
l_int32 l_dnaGetCount (L_DNA *da)
 
l_ok l_dnaSetCount (L_DNA *da, l_int32 newcount)
 
l_ok l_dnaGetDValue (L_DNA *da, l_int32 index, l_float64 *pval)
 
l_ok l_dnaGetIValue (L_DNA *da, l_int32 index, l_int32 *pival)
 
l_ok l_dnaSetValue (L_DNA *da, l_int32 index, l_float64 val)
 
l_ok l_dnaShiftValue (L_DNA *da, l_int32 index, l_float64 diff)
 
l_int32 * l_dnaGetIArray (L_DNA *da)
 
l_float64 * l_dnaGetDArray (L_DNA *da, l_int32 copyflag)
 
l_int32 l_dnaGetRefcount (L_DNA *da)
 
l_ok l_dnaChangeRefcount (L_DNA *da, l_int32 delta)
 
l_ok l_dnaGetParameters (L_DNA *da, l_float64 *pstartx, l_float64 *pdelx)
 
l_ok l_dnaSetParameters (L_DNA *da, l_float64 startx, l_float64 delx)
 
l_ok l_dnaCopyParameters (L_DNA *dad, L_DNA *das)
 
L_DNAl_dnaRead (const char *filename)
 
L_DNAl_dnaReadStream (FILE *fp)
 
l_ok l_dnaWrite (const char *filename, L_DNA *da)
 
l_ok l_dnaWriteStream (FILE *fp, L_DNA *da)
 
L_DNAAl_dnaaCreate (l_int32 n)
 
L_DNAAl_dnaaCreateFull (l_int32 nptr, l_int32 n)
 
l_ok l_dnaaTruncate (L_DNAA *daa)
 
void l_dnaaDestroy (L_DNAA **pdaa)
 
l_ok l_dnaaAddDna (L_DNAA *daa, L_DNA *da, l_int32 copyflag)
 
l_int32 l_dnaaGetCount (L_DNAA *daa)
 
l_int32 l_dnaaGetDnaCount (L_DNAA *daa, l_int32 index)
 
l_int32 l_dnaaGetNumberCount (L_DNAA *daa)
 
L_DNAl_dnaaGetDna (L_DNAA *daa, l_int32 index, l_int32 accessflag)
 
l_ok l_dnaaReplaceDna (L_DNAA *daa, l_int32 index, L_DNA *da)
 
l_ok l_dnaaGetValue (L_DNAA *daa, l_int32 i, l_int32 j, l_float64 *pval)
 
l_ok l_dnaaAddNumber (L_DNAA *daa, l_int32 index, l_float64 val)
 
L_DNAAl_dnaaRead (const char *filename)
 
L_DNAAl_dnaaReadStream (FILE *fp)
 
l_ok l_dnaaWrite (const char *filename, L_DNAA *daa)
 
l_ok l_dnaaWriteStream (FILE *fp, L_DNAA *daa)
 

Variables

static const l_int32 INITIAL_PTR_ARRAYSIZE = 50
 

Detailed Description

 Dna creation, destruction, copy, clone, etc.
     L_DNA       *l_dnaCreate()
     L_DNA       *l_dnaCreateFromIArray()
     L_DNA       *l_dnaCreateFromDArray()
     L_DNA       *l_dnaMakeSequence()
     void        *l_dnaDestroy()
     L_DNA       *l_dnaCopy()
     L_DNA       *l_dnaClone()
     l_int32      l_dnaEmpty()

 Dna: add/remove number and extend array
     l_int32      l_dnaAddNumber()
     static l_int32  l_dnaExtendArray()
     l_int32      l_dnaInsertNumber()
     l_int32      l_dnaRemoveNumber()
     l_int32      l_dnaReplaceNumber()

 Dna accessors
     l_int32      l_dnaGetCount()
     l_int32      l_dnaSetCount()
     l_int32      l_dnaGetIValue()
     l_int32      l_dnaGetDValue()
     l_int32      l_dnaSetValue()
     l_int32      l_dnaShiftValue()
     l_int32     *l_dnaGetIArray()
     l_float64   *l_dnaGetDArray()
     l_int32      l_dnaGetRefcount()
     l_int32      l_dnaChangeRefcount()
     l_int32      l_dnaGetParameters()
     l_int32      l_dnaSetParameters()
     l_int32      l_dnaCopyParameters()

 Serialize Dna for I/O
     L_DNA       *l_dnaRead()
     L_DNA       *l_dnaReadStream()
     l_int32      l_dnaWrite()
     l_int32      l_dnaWriteStream()

 Dnaa creation, destruction
     L_DNAA      *l_dnaaCreate()
     L_DNAA      *l_dnaaCreateFull()
     l_int32      l_dnaaTruncate()
     void        *l_dnaaDestroy()

 Add Dna to Dnaa
     l_int32      l_dnaaAddDna()
     static l_int32  l_dnaaExtendArray()

 Dnaa accessors
     l_int32      l_dnaaGetCount()
     l_int32      l_dnaaGetDnaCount()
     l_int32      l_dnaaGetNumberCount()
     L_DNA       *l_dnaaGetDna()
     L_DNA       *l_dnaaReplaceDna()
     l_int32      l_dnaaGetValue()
     l_int32      l_dnaaAddNumber()

 Serialize Dnaa for I/O
     L_DNAA      *l_dnaaRead()
     L_DNAA      *l_dnaaReadStream()
     l_int32      l_dnaaWrite()
     l_int32      l_dnaaWriteStream()
   (1) The Dna is a struct holding an array of doubles.  It can also
       be used to store l_int32 values, up to the full precision
       of int32.  Always use it whenever integers larger than a
       few million need to be stored.
   (2) Always use the accessors in this file, never the fields directly.
   (3) Storing and retrieving numbers:
      * to append a new number to the array, use l_dnaAddNumber().  If
        the number is an int, it will will automatically be converted
        to l_float64 and stored.
      * to reset a value stored in the array, use l_dnaSetValue().
      * to increment or decrement a value stored in the array,
        use l_dnaShiftValue().
      * to obtain a value from the array, use either l_dnaGetIValue()
        or l_dnaGetDValue(), depending on whether you are retrieving
        an integer or a float64.  This avoids doing an explicit cast,
        such as
          (a) return a l_float64 and cast it to an l_int32
          (b) cast the return directly to (l_float64 *) to
              satisfy the function prototype, as in
                l_dnaGetDValue(da, index, (l_float64 *)&ival);   [ugly!]
   (4) int <–> double conversions:
Conversions go automatically from l_int32 --> l_float64,
without loss of precision.  You must cast (l_int32)
to go from l_float64 --> l_int32 because you're truncating
to the integer value.
   (5) As with other arrays in leptonica, the l_dna has both an allocated
       size and a count of the stored numbers.  When you add a number, it
       goes on the end of the array, and causes a realloc if the array
       is already filled.  However, in situations where you want to
       add numbers randomly into an array, such as when you build a
       histogram, you must set the count of stored numbers in advance.
       This is done with l_dnaSetCount().  If you set a count larger
       than the allocated array, it does a realloc to the size requested.
   (6) In situations where the data in a l_dna correspond to a function
       y(x), the values can be either at equal spacings in x or at
       arbitrary spacings.  For the former, we can represent all x values
       by two parameters: startx (corresponding to y[0]) and delx
       for the change in x for adjacent values y[i] and y[i+1].
       startx and delx are initialized to 0.0 and 1.0, rsp.
       For arbitrary spacings, we use a second l_dna, and the two
       l_dnas are typically denoted dnay and dnax.

Definition in file dnabasic.c.

Function Documentation

◆ l_dnaaAddDna()

l_ok l_dnaaAddDna ( L_DNAA daa,
L_DNA da,
l_int32  copyflag 
)

l_dnaaAddDna()

Parameters
[in]daa
[in]dato be added
[in]copyflagL_INSERT, L_COPY, L_CLONE
Returns
0 if OK, 1 on error

Definition at line 1265 of file dnabasic.c.

References L_Dnaa::dna, L_CLONE, L_COPY, l_dnaaExtendArray(), l_dnaaGetCount(), l_dnaClone(), l_dnaCopy(), L_INSERT, L_Dnaa::n, and L_Dnaa::nalloc.

Referenced by l_dnaaCreateFull(), l_dnaaReadStream(), and ptraConcatenatePdfToData().

◆ l_dnaaAddNumber()

l_ok l_dnaaAddNumber ( L_DNAA daa,
l_int32  index,
l_float64  val 
)

l_dnaaAddNumber()

Parameters
[in]daa
[in]indexof l_dna within l_dnaa
[in]valnumber to be added; stored as a double
Returns
0 if OK, 1 on error
Notes:
     (1) Adds to an existing l_dna only.

Definition at line 1510 of file dnabasic.c.

References L_CLONE, l_dnaAddNumber(), l_dnaaGetCount(), l_dnaaGetDna(), and l_dnaDestroy().

◆ l_dnaaCreate()

L_DNAA* l_dnaaCreate ( l_int32  n)

l_dnaaCreate()

Parameters
[in]nsize of l_dna ptr array to be alloc'd 0 for default
Returns
daa, or NULL on error

Definition at line 1127 of file dnabasic.c.

References L_Dnaa::dna, INITIAL_PTR_ARRAYSIZE, l_dnaaDestroy(), L_Dnaa::n, and L_Dnaa::nalloc.

Referenced by l_dnaaCreateFull(), l_dnaaReadStream(), and ptraConcatenatePdfToData().

◆ l_dnaaCreateFull()

L_DNAA* l_dnaaCreateFull ( l_int32  nptr,
l_int32  n 
)

l_dnaaCreateFull()

Parameters
[in]nptrsize of dna ptr array to be alloc'd
[in]nsize of individual dna arrays to be alloc'd 0 for default
Returns
daa, or NULL on error
Notes:
     (1) This allocates a dnaa and fills the array with allocated dnas.
         In use, after calling this function, use
             l_dnaaAddNumber(dnaa, index, val);
         to add val to the index-th dna in dnaa.

Definition at line 1163 of file dnabasic.c.

References l_dnaaAddDna(), l_dnaaCreate(), l_dnaCreate(), and L_INSERT.

◆ l_dnaAddNumber()

◆ l_dnaaDestroy()

void l_dnaaDestroy ( L_DNAA **  pdaa)

l_dnaaDestroy()

Parameters
[in,out]pdaato be nulled if it exists
Returns
void

Definition at line 1228 of file dnabasic.c.

References L_Dnaa::dna, l_dnaDestroy(), and L_Dnaa::n.

Referenced by l_dnaaCreate(), l_dnaaReadStream(), and ptraConcatenatePdfToData().

◆ l_dnaaExtendArray()

static l_int32 l_dnaaExtendArray ( L_DNAA daa)
static

l_dnaaExtendArray()

Parameters
[in]daa
Returns
0 if OK, 1 on error

Definition at line 1306 of file dnabasic.c.

References L_Dnaa::dna, L_Dnaa::nalloc, and reallocNew().

Referenced by l_dnaaAddDna().

◆ l_dnaaGetCount()

l_int32 l_dnaaGetCount ( L_DNAA daa)

l_dnaaGetCount()

Parameters
[in]daa
Returns
count number of l_dna, or 0 if no l_dna or on error

Definition at line 1333 of file dnabasic.c.

References L_Dnaa::n.

Referenced by l_dnaaAddDna(), l_dnaaAddNumber(), l_dnaaGetNumberCount(), l_dnaaGetValue(), l_dnaaReplaceDna(), l_dnaaTruncate(), and l_dnaaWriteStream().

◆ l_dnaaGetDna()

L_DNA* l_dnaaGetDna ( L_DNAA daa,
l_int32  index,
l_int32  accessflag 
)

l_dnaaGetDna()

Parameters
[in]daa
[in]indexto the index-th l_dna
[in]accessflagL_COPY or L_CLONE
Returns
l_dna, or NULL on error

Definition at line 1402 of file dnabasic.c.

References L_Dnaa::dna, L_CLONE, L_COPY, l_dnaClone(), l_dnaCopy(), and L_Dnaa::n.

Referenced by l_dnaaAddNumber(), l_dnaaGetNumberCount(), l_dnaaTruncate(), l_dnaaWriteStream(), and ptraConcatenatePdfToData().

◆ l_dnaaGetDnaCount()

l_int32 l_dnaaGetDnaCount ( L_DNAA daa,
l_int32  index 
)

l_dnaaGetDnaCount()

Parameters
[in]daa
[in]indexof l_dna in daa
Returns
count of numbers in the referenced l_dna, or 0 on error.

Definition at line 1351 of file dnabasic.c.

References L_Dnaa::dna, l_dnaGetCount(), and L_Dnaa::n.

◆ l_dnaaGetNumberCount()

l_int32 l_dnaaGetNumberCount ( L_DNAA daa)

l_dnaaGetNumberCount()

Parameters
[in]daa
Returns
count total number of numbers in the l_dnaa, or 0 if no numbers or on error

Definition at line 1372 of file dnabasic.c.

References L_CLONE, l_dnaaGetCount(), l_dnaaGetDna(), l_dnaDestroy(), and l_dnaGetCount().

◆ l_dnaaGetValue()

l_ok l_dnaaGetValue ( L_DNAA daa,
l_int32  i,
l_int32  j,
l_float64 *  pval 
)

l_dnaaGetValue()

Parameters
[in]daa
[in]iindex of l_dna within l_dnaa
[in]jindex into l_dna
[out]pvaldouble value
Returns
0 if OK, 1 on error

Definition at line 1470 of file dnabasic.c.

References L_Dna::array, L_Dnaa::dna, l_dnaaGetCount(), and L_Dna::n.

◆ l_dnaaRead()

L_DNAA* l_dnaaRead ( const char *  filename)

l_dnaaRead()

Parameters
[in]filename
Returns
daa, or NULL on error

Definition at line 1542 of file dnabasic.c.

References fopenReadStream(), and l_dnaaReadStream().

◆ l_dnaaReadStream()

L_DNAA* l_dnaaReadStream ( FILE *  fp)

l_dnaaReadStream()

Parameters
[in]fpfile stream
Returns
daa, or NULL on error

Definition at line 1569 of file dnabasic.c.

References DNA_VERSION_NUMBER, l_dnaaAddDna(), l_dnaaCreate(), l_dnaaDestroy(), l_dnaReadStream(), and L_INSERT.

Referenced by l_dnaaRead().

◆ l_dnaaReplaceDna()

l_ok l_dnaaReplaceDna ( L_DNAA daa,
l_int32  index,
L_DNA da 
)

l_dnaaReplaceDna()

Parameters
[in]daa
[in]indexto the index-th l_dna
[in]dainsert and replace any existing one
Returns
0 if OK, 1 on error
Notes:
     (1) Any existing l_dna is destroyed, and the input one
         is inserted in its place.
     (2) If the index is invalid, return 1 (error)

Definition at line 1438 of file dnabasic.c.

References L_Dnaa::dna, l_dnaaGetCount(), and l_dnaDestroy().

◆ l_dnaaTruncate()

l_ok l_dnaaTruncate ( L_DNAA daa)

l_dnaaTruncate()

Parameters
[in]daa
Returns
0 if OK, 1 on error
Notes:
     (1) This identifies the largest index containing a dna that
         has any numbers within it, destroys all dna beyond that
         index, and resets the count.

Definition at line 1194 of file dnabasic.c.

References L_Dnaa::dna, L_CLONE, l_dnaaGetCount(), l_dnaaGetDna(), l_dnaDestroy(), l_dnaGetCount(), and L_Dnaa::n.

◆ l_dnaaWrite()

l_ok l_dnaaWrite ( const char *  filename,
L_DNAA daa 
)

l_dnaaWrite()

Parameters
[in]filename,daa
Returns
0 if OK, 1 on error

Definition at line 1613 of file dnabasic.c.

References fopenWriteStream(), and l_dnaaWriteStream().

◆ l_dnaaWriteStream()

l_ok l_dnaaWriteStream ( FILE *  fp,
L_DNAA daa 
)

l_dnaaWriteStream()

Parameters
[in]fpfile stream
[in]daa
Returns
0 if OK, 1 on error

Definition at line 1644 of file dnabasic.c.

References DNA_VERSION_NUMBER, L_CLONE, l_dnaaGetCount(), l_dnaaGetDna(), l_dnaDestroy(), and l_dnaWriteStream().

Referenced by l_dnaaWrite().

◆ l_dnaChangeRefcount()

l_ok l_dnaChangeRefcount ( L_DNA da,
l_int32  delta 
)

l_dnaChangeRefCount()

Parameters
[in]da
[in]deltachange to be applied
Returns
0 if OK, 1 on error

Definition at line 881 of file dnabasic.c.

References L_Dna::refcount.

Referenced by l_dnaClone(), and l_dnaDestroy().

◆ l_dnaClone()

L_DNA* l_dnaClone ( L_DNA da)

l_dnaClone()

Parameters
[in]da
Returns
ptr to same da, or NULL on error

Definition at line 389 of file dnabasic.c.

References l_dnaChangeRefcount().

Referenced by l_dnaaAddDna(), l_dnaaGetDna(), and l_dnaHashGetDna().

◆ l_dnaCopy()

L_DNA* l_dnaCopy ( L_DNA da)

l_dnaCopy()

Parameters
[in]da
Returns
copy of da, or NULL on error
Notes:
     (1) This removes unused ptrs above da->n.

Definition at line 360 of file dnabasic.c.

References L_Dna::array, L_Dna::delx, l_dnaAddNumber(), l_dnaCreate(), L_Dna::n, and L_Dna::startx.

Referenced by l_dnaaAddDna(), l_dnaaGetDna(), l_dnaHashGetDna(), and l_dnaUnionByAset().

◆ l_dnaCopyParameters()

l_ok l_dnaCopyParameters ( L_DNA dad,
L_DNA das 
)

l_dnaCopyParameters()

Parameters
[in]daddestination DNuma
[in]dassource DNuma
Returns
0 if OK, 1 on error

Definition at line 955 of file dnabasic.c.

References l_dnaGetParameters(), and l_dnaSetParameters().

◆ l_dnaCreate()

◆ l_dnaCreateFromDArray()

L_DNA* l_dnaCreateFromDArray ( l_float64 *  darray,
l_int32  size,
l_int32  copyflag 
)

l_dnaCreateFromDArray()

Parameters
[in]darrayfloat
[in]sizeof the array
[in]copyflagL_INSERT or L_COPY
Returns
da, or NULL on error
Notes:
     (1) With L_INSERT, ownership of the input array is transferred
         to the returned l_dna, and all size elements are considered
         to be valid.

Definition at line 247 of file dnabasic.c.

References L_Dna::array, L_COPY, l_dnaAddNumber(), l_dnaCreate(), L_INSERT, and L_Dna::n.

◆ l_dnaCreateFromIArray()

L_DNA* l_dnaCreateFromIArray ( l_int32 *  iarray,
l_int32  size 
)

l_dnaCreateFromIArray()

Parameters
[in]iarrayinteger
[in]sizeof the array
Returns
da, or NULL on error
Notes:
     (1) We can't insert this int array into the l_dna, because a l_dna
         takes a double array.  So this just copies the data from the
         input array into the l_dna.  The input array continues to be
         owned by the caller.

Definition at line 210 of file dnabasic.c.

References l_dnaAddNumber(), and l_dnaCreate().

◆ l_dnaDestroy()

void l_dnaDestroy ( L_DNA **  pda)

l_dnaDestroy()

Parameters
[in,out]pdato be nulled if it exists
Returns
void
Notes:
     (1) Decrements the ref count and, if 0, destroys the l_dna.
     (2) Always nulls the input ptr.

Definition at line 321 of file dnabasic.c.

References L_Dna::array, l_dnaChangeRefcount(), and l_dnaGetRefcount().

Referenced by arrayFindEachSequence(), l_dnaaAddNumber(), l_dnaaDestroy(), l_dnaaGetNumberCount(), l_dnaaReplaceDna(), l_dnaaTruncate(), l_dnaaWriteStream(), l_dnaCreate(), l_dnaHashDestroy(), l_dnaReadStream(), l_dnaUnionByAset(), parseTrailerPdf(), ptraConcatenatePdfToData(), recogDestroy(), and substituteObjectNumbers().

◆ l_dnaEmpty()

l_ok l_dnaEmpty ( L_DNA da)

l_dnaEmpty()

Parameters
[in]da
Returns
0 if OK; 1 on error
Notes:
     (1) This does not change the allocation of the array.
         It just clears the number of stored numbers, so that
         the array appears to be empty.

Definition at line 415 of file dnabasic.c.

References L_Dna::n.

Referenced by parseTrailerPdf().

◆ l_dnaExtendArray()

static l_int32 l_dnaExtendArray ( L_DNA da)
static

l_dnaExtendArray()

Parameters
[in]da
Returns
0 if OK, 1 on error

Definition at line 465 of file dnabasic.c.

References L_Dna::array, L_Dna::nalloc, and reallocNew().

Referenced by l_dnaAddNumber(), and l_dnaInsertNumber().

◆ l_dnaGetCount()

◆ l_dnaGetDArray()

l_float64* l_dnaGetDArray ( L_DNA da,
l_int32  copyflag 
)

l_dnaGetDArray()

Parameters
[in]da
[in]copyflagL_NOCOPY or L_COPY
Returns
either the bare internal array or a copy of it, or NULL on error
Notes:
     (1) If copyflag == L_COPY, it makes a copy which the caller
         is responsible for freeing.  Otherwise, it operates
         directly on the bare array of the l_dna.
     (2) Very important: for L_NOCOPY, any writes to the array
         will be in the l_dna.  Do not write beyond the size of
         the count field, because it will not be accessible
         from the l_dna!  If necessary, be sure to set the count
         field to a larger number (such as the alloc size)
         BEFORE calling this function.  Creating with l_dnaMakeConstant()
         is another way to insure full initialization.

Definition at line 831 of file dnabasic.c.

References L_Dna::array, l_dnaGetCount(), and L_NOCOPY.

◆ l_dnaGetDValue()

l_ok l_dnaGetDValue ( L_DNA da,
l_int32  index,
l_float64 *  pval 
)

l_dnaGetDValue()

Parameters
[in]da
[in]indexinto l_dna
[out]pvaldouble value; 0.0 on error
Returns
0 if OK; 1 on error
Notes:
     (1) Caller may need to check the function return value to
         decide if a 0.0 in the returned ival is valid.

Definition at line 658 of file dnabasic.c.

References L_Dna::array, and L_Dna::n.

Referenced by l_dnaConvertToNuma(), l_dnaFindValByHash(), l_dnaHashCreateFromDna(), l_dnaIntersectionByHash(), l_dnaJoin(), l_dnaMakeHistoByHash(), and l_dnaRemoveDupsByHash().

◆ l_dnaGetIArray()

l_int32* l_dnaGetIArray ( L_DNA da)

l_dnaGetIArray()

Parameters
[in]da
Returns
a copy of the bare internal array, integerized by rounding, or NULL on error
Notes:
     (1) A copy of the array is made, because we need to
         generate an integer array from the bare double array.
         The caller is responsible for freeing the array.
     (2) The array size is determined by the number of stored numbers,
         not by the size of the allocated array in the l_dna.
     (3) This function is provided to simplify calculations
         using the bare internal array, rather than continually
         calling accessors on the l_dna.  It is typically used
         on an array of size 256.

Definition at line 786 of file dnabasic.c.

References l_dnaGetCount(), and l_dnaGetIValue().

Referenced by generateOutputDataPdf(), and substituteObjectNumbers().

◆ l_dnaGetIValue()

l_ok l_dnaGetIValue ( L_DNA da,
l_int32  index,
l_int32 *  pival 
)

l_dnaGetIValue()

Parameters
[in]da
[in]indexinto l_dna
[out]pivalinteger value; 0 on error
Returns
0 if OK; 1 on error
Notes:
     (1) Caller may need to check the function return value to
         decide if a 0 in the returned ival is valid.

Definition at line 693 of file dnabasic.c.

References L_Dna::array, and L_Dna::n.

Referenced by l_dnaDiffAdjValues(), l_dnaFindValByHash(), l_dnaGetIArray(), l_dnaMakeHistoByHash(), parseTrailerPdf(), ptaFindPtByHash(), recogGetClassIndex(), recogShowContent(), and sarrayFindStringByHash().

◆ l_dnaGetParameters()

l_ok l_dnaGetParameters ( L_DNA da,
l_float64 *  pstartx,
l_float64 *  pdelx 
)

l_dnaGetParameters()

Parameters
[in]da
[out]pstartx[optional] startx
[out]pdelx[optional] delx
Returns
0 if OK, 1 on error

Definition at line 902 of file dnabasic.c.

References L_Dna::delx, and L_Dna::startx.

Referenced by l_dnaCopyParameters(), and l_dnaWriteStream().

◆ l_dnaGetRefcount()

l_int32 l_dnaGetRefcount ( L_DNA da)

l_dnaGetRefCount()

Parameters
[in]da
Returns
refcount, or UNDEF on error

Definition at line 863 of file dnabasic.c.

References L_Dna::refcount.

Referenced by l_dnaDestroy().

◆ l_dnaInsertNumber()

l_ok l_dnaInsertNumber ( L_DNA da,
l_int32  index,
l_float64  val 
)

l_dnaInsertNumber()

Parameters
[in]da
[in]indexlocation in da to insert new value
[in]valfloat64 or integer to be added
Returns
0 if OK, 1 on error
Notes:
     (1) This shifts da[i] –> da[i + 1] for all i >= index,
         and then inserts val as da[index].
     (2) It should not be used repeatedly on large arrays,
         because the function is O(n).
 

Definition at line 500 of file dnabasic.c.

References L_Dna::array, l_dnaExtendArray(), l_dnaGetCount(), L_Dna::n, and L_Dna::nalloc.

◆ l_dnaMakeSequence()

L_DNA* l_dnaMakeSequence ( l_float64  startval,
l_float64  increment,
l_int32  size 
)

l_dnaMakeSequence()

Parameters
[in]startval
[in]increment
[in]sizeof sequence
Returns
l_dna of sequence of evenly spaced values, or NULL on error

Definition at line 286 of file dnabasic.c.

References l_dnaAddNumber(), and l_dnaCreate().

◆ l_dnaRead()

L_DNA* l_dnaRead ( const char *  filename)

l_dnaRead()

Parameters
[in]filename
Returns
da, or NULL on error

Definition at line 981 of file dnabasic.c.

References fopenReadStream(), and l_dnaReadStream().

◆ l_dnaReadStream()

L_DNA* l_dnaReadStream ( FILE *  fp)

l_dnaReadStream()

Parameters
[in]fpfile stream
Returns
da, or NULL on error
Notes:
     (1) fscanf takes lf to read a double; fprintf takes f to write it.

Definition at line 1013 of file dnabasic.c.

References DNA_VERSION_NUMBER, l_dnaAddNumber(), l_dnaCreate(), l_dnaDestroy(), and l_dnaSetParameters().

Referenced by l_dnaaReadStream(), and l_dnaRead().

◆ l_dnaRemoveNumber()

l_ok l_dnaRemoveNumber ( L_DNA da,
l_int32  index 
)

l_dnaRemoveNumber()

Parameters
[in]da
[in]indexelement to be removed
Returns
0 if OK, 1 on error
Notes:
     (1) This shifts da[i] –> da[i - 1] for all i > index.
     (2) It should not be used repeatedly on large arrays,
         because the function is O(n).

Definition at line 539 of file dnabasic.c.

References L_Dna::array, l_dnaGetCount(), and L_Dna::n.

◆ l_dnaReplaceNumber()

l_ok l_dnaReplaceNumber ( L_DNA da,
l_int32  index,
l_float64  val 
)

l_dnaReplaceNumber()

Parameters
[in]da
[in]indexelement to be replaced
[in]valnew value to replace old one
Returns
0 if OK, 1 on error

Definition at line 568 of file dnabasic.c.

References L_Dna::array, and l_dnaGetCount().

◆ l_dnaSetCount()

l_ok l_dnaSetCount ( L_DNA da,
l_int32  newcount 
)

l_dnaSetCount()

Parameters
[in]da
[in]newcount
Returns
0 if OK, 1 on error
Notes:
     (1) If newcount <= da->nalloc, this resets da->n.
         Using newcount = 0 is equivalent to l_dnaEmpty().
     (2) If newcount > da->nalloc, this causes a realloc
         to a size da->nalloc = newcount.
     (3) All the previously unused values in da are set to 0.0.

Definition at line 624 of file dnabasic.c.

References L_Dna::array, L_Dna::n, L_Dna::nalloc, and reallocNew().

◆ l_dnaSetParameters()

l_ok l_dnaSetParameters ( L_DNA da,
l_float64  startx,
l_float64  delx 
)

l_dnaSetParameters()

Parameters
[in]da
[in]startxx value corresponding to da[0]
[in]delxdifference in x values for the situation where the elements of da correspond to the evaulation of a function at equal intervals of size delx
Returns
0 if OK, 1 on error

Definition at line 932 of file dnabasic.c.

References L_Dna::delx, and L_Dna::startx.

Referenced by l_dnaCopyParameters(), and l_dnaReadStream().

◆ l_dnaSetValue()

l_ok l_dnaSetValue ( L_DNA da,
l_int32  index,
l_float64  val 
)

l_dnaSetValue()

Parameters
[in]da
[in]indexto element to be set
[in]valto set element
Returns
0 if OK; 1 on error

Definition at line 725 of file dnabasic.c.

References L_Dna::array, and L_Dna::n.

Referenced by l_dnaMakeHistoByHash().

◆ l_dnaShiftValue()

l_ok l_dnaShiftValue ( L_DNA da,
l_int32  index,
l_float64  diff 
)

l_dnaShiftValue()

Parameters
[in]da
[in]indexto element to change relative to the current value
[in]diffincrement if diff > 0 or decrement if diff < 0
Returns
0 if OK; 1 on error

Definition at line 750 of file dnabasic.c.

References L_Dna::array, and L_Dna::n.

◆ l_dnaWrite()

l_ok l_dnaWrite ( const char *  filename,
L_DNA da 
)

l_dnaWrite()

Parameters
[in]filename,da
Returns
0 if OK, 1 on error

Definition at line 1056 of file dnabasic.c.

References fopenWriteStream(), and l_dnaWriteStream().

◆ l_dnaWriteStream()

l_ok l_dnaWriteStream ( FILE *  fp,
L_DNA da 
)

l_dnaWriteStream()

Parameters
[in]fpfile stream
[in]da
Returns
0 if OK, 1 on error

Definition at line 1087 of file dnabasic.c.

References L_Dna::array, DNA_VERSION_NUMBER, l_dnaGetCount(), and l_dnaGetParameters().

Referenced by l_dnaaWriteStream(), l_dnaWrite(), and parseTrailerPdf().

Variable Documentation

◆ INITIAL_PTR_ARRAYSIZE

const l_int32 INITIAL_PTR_ARRAYSIZE = 50
static

n'importe quoi

Definition at line 152 of file dnabasic.c.

Referenced by l_dnaaCreate(), and l_dnaCreate().