Leptonica  1.82.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_DNAl_dnaReadMem (const l_uint8 *data, size_t size)
 
l_ok l_dnaWrite (const char *filename, L_DNA *da)
 
l_ok l_dnaWriteStream (FILE *fp, L_DNA *da)
 
l_ok l_dnaWriteStderr (L_DNA *da)
 
l_ok l_dnaWriteMem (l_uint8 **pdata, size_t *psize, 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_DNAAl_dnaaReadMem (const l_uint8 *data, size_t size)
 
l_ok l_dnaaWrite (const char *filename, L_DNAA *daa)
 
l_ok l_dnaaWriteStream (FILE *fp, L_DNAA *daa)
 
l_ok l_dnaaWriteMem (l_uint8 **pdata, size_t *psize, L_DNAA *daa)
 

Variables

static const l_uint32 MaxDoubleArraySize = 100000000
 
static const l_uint32 MaxPtrArraySize = 1000000
 
static const l_int32 InitialArraySize = 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_DNA       *l_dnaReadMem()
         l_int32      l_dnaWrite()
         l_int32      l_dnaWriteStream()
         l_int32      l_dnaWriteStderr()
         l_int32      l_dnaWriteMem()
     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_DNAA      *l_dnaaReadMem()
         l_int32      l_dnaaWrite()
         l_int32      l_dnaaWriteStream()
         l_int32      l_dnaaWriteMem()
   (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 1421 of file dnabasic.c.

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

Referenced by evalColorfillData(), l_dnaaCreateFull(), 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 1684 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 1285 of file dnabasic.c.

Referenced by l_dnaaCreateFull(), 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 1321 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]pdaawill be set to null before returning
Returns
void

Definition at line 1386 of file dnabasic.c.

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

Referenced by l_colorfillDestroy(), 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
Notes:
     (1) Doubles the number of dna ptrs.
     (2) The max size of the dna array is 1M ptrs.

Definition at line 1473 of file dnabasic.c.

References L_Dnaa::nalloc.

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 1507 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 1576 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 1525 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 1546 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 1644 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 1716 of file dnabasic.c.

References fopenReadStream(), and l_dnaaReadStream().

◆ l_dnaaReadMem()

L_DNAA* l_dnaaReadMem ( const l_uint8 *  data,
size_t  size 
)

l_dnaaReadMem()

Parameters
[in]datadnaa serialization; in ascii
[in]sizeof data; can use strlen to get it
Returns
daa, or NULL on error

Definition at line 1798 of file dnabasic.c.

References fopenReadFromMemory(), and l_dnaaReadStream().

◆ l_dnaaReadStream()

L_DNAA* l_dnaaReadStream ( FILE *  fp)

l_dnaaReadStream()

Parameters
[in]fpfile stream
Returns
daa, or NULL on error
Notes:
     (1) It is OK for the dnaa to be empty.

Definition at line 1748 of file dnabasic.c.

References DNA_VERSION_NUMBER.

Referenced by l_dnaaRead(), and l_dnaaReadMem().

◆ 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 index is invalid, return 1 (error)

Definition at line 1612 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 1352 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
[in]daa
Returns
0 if OK, 1 on error

Definition at line 1826 of file dnabasic.c.

References fopenWriteStream(), and l_dnaaWriteStream().

◆ l_dnaaWriteMem()

l_ok l_dnaaWriteMem ( l_uint8 **  pdata,
size_t *  psize,
L_DNAA daa 
)

l_dnaaWriteMem()

Parameters
[out]pdatadata of serialized dnaa; ascii
[out]psizesize of returned data
[in]daa
Returns
0 if OK, 1 on error
Notes:
     (1) Serializes a dnaa in memory and puts the result in a buffer.

Definition at line 1899 of file dnabasic.c.

References fopenWriteWinTempfile(), l_binaryReadStream(), 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 1857 of file dnabasic.c.

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

Referenced by l_dnaaWrite(), and l_dnaaWriteMem().

◆ 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 914 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 398 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 369 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(), l_dnaSelectRange(), l_dnaUnionByAset(), and l_dnaUnionByHmap().

◆ 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 988 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 258 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 array
[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 221 of file dnabasic.c.

References l_dnaAddNumber(), and l_dnaCreate().

◆ l_dnaDestroy()

void l_dnaDestroy ( L_DNA **  pda)

l_dnaDestroy()

Parameters
[in,out]pdawill be set to null before returning
Returns
void
Notes:
     (1) Decrements the ref count and, if 0, destroys the l_dna.
     (2) Always nulls the input ptr.

Definition at line 332 of file dnabasic.c.

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

Referenced by arrayFindEachSequence(), arrayReplaceEachSequence(), l_dnaaAddDna(), l_dnaaAddNumber(), l_dnaaDestroy(), l_dnaaGetNumberCount(), l_dnaaReplaceDna(), l_dnaaTruncate(), l_dnaaWriteStream(), l_dnaHashDestroy(), l_dnaUnionByAset(), l_dnaUnionByHmap(), makeColorfillTestData(), 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 424 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
Notes:
     (1) Doubles the size of the array.
     (2) The max number of doubles is 100M.

Definition at line 482 of file dnabasic.c.

References L_Dna::nalloc.

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 864 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 692 of file dnabasic.c.

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

Referenced by l_dnaConvertToNuma(), l_dnaIntersectionByHmap(), l_dnaJoin(), l_dnaMakeHistoByHmap(), l_dnaRemoveDupsByHmap(), l_dnaSelectRange(), l_hmapCreateFromDna(), and makeColorfillTestData().

◆ 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 820 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 727 of file dnabasic.c.

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

Referenced by arrayReplaceEachSequence(), l_dnaDiffAdjValues(), l_dnaGetIArray(), parseTrailerPdf(), recogGetClassIndex(), and recogShowContent().

◆ 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 935 of file dnabasic.c.

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

Referenced by l_dnaCopyParameters(), l_dnaWriteStderr(), 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 896 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 526 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 297 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 1014 of file dnabasic.c.

References fopenReadStream(), and l_dnaReadStream().

◆ l_dnaReadMem()

L_DNA* l_dnaReadMem ( const l_uint8 *  data,
size_t  size 
)

l_dnaReadMem()

Parameters
[in]datadna serialization; in ascii
[in]sizeof data; can use strlen to get it
Returns
da, or NULL on error

Definition at line 1096 of file dnabasic.c.

References fopenReadFromMemory(), 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.
     (2) It is OK for the dna to be empty.

Definition at line 1047 of file dnabasic.c.

References DNA_VERSION_NUMBER.

Referenced by l_dnaRead(), and l_dnaReadMem().

◆ 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 569 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 600 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 658 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 evaluation of a function at equal intervals of size delx
Returns
0 if OK, 1 on error

Definition at line 965 of file dnabasic.c.

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

Referenced by l_dnaCopyParameters().

◆ 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 759 of file dnabasic.c.

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

◆ 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 784 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
[in]da
Returns
0 if OK, 1 on error

Definition at line 1124 of file dnabasic.c.

References fopenWriteStream(), and l_dnaWriteStream().

◆ l_dnaWriteMem()

l_ok l_dnaWriteMem ( l_uint8 **  pdata,
size_t *  psize,
L_DNA da 
)

l_dnaWriteMem()

Parameters
[out]pdatadata of serialized dna; ascii
[out]psizesize of returned data
[in]da
Returns
0 if OK, 1 on error
Notes:
     (1) Serializes a dna in memory and puts the result in a buffer.

Definition at line 1231 of file dnabasic.c.

References fopenWriteWinTempfile(), l_binaryReadStream(), and l_dnaWriteStream().

◆ l_dnaWriteStderr()

l_ok l_dnaWriteStderr ( L_DNA da)

l_dnaWriteStrderr()

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

Definition at line 1191 of file dnabasic.c.

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

Referenced by l_dnaWriteStream(), and parseTrailerPdf().

◆ l_dnaWriteStream()

l_ok l_dnaWriteStream ( FILE *  fp,
L_DNA da 
)

l_dnaWriteStream()

Parameters
[in]fpfile stream; use NULL to write to stderr
[in]da
Returns
0 if OK, 1 on error

Definition at line 1155 of file dnabasic.c.

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

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

Variable Documentation

◆ InitialArraySize

const l_int32 InitialArraySize = 50
static

n'importe quoi

Definition at line 164 of file dnabasic.c.