Leptonica  1.82.0
Image processing and image analysis suite
dnafunc1.c File Reference
#include "allheaders.h"

Go to the source code of this file.

Functions

l_ok l_dnaJoin (L_DNA *dad, L_DNA *das, l_int32 istart, l_int32 iend)
 
L_DNAl_dnaaFlattenToDna (L_DNAA *daa)
 
L_DNAl_dnaSelectRange (L_DNA *das, l_int32 first, l_int32 last)
 
NUMAl_dnaConvertToNuma (L_DNA *da)
 
L_DNAnumaConvertToDna (NUMA *na)
 
L_DNApixConvertDataToDna (PIX *pix)
 
L_ASETl_asetCreateFromDna (L_DNA *da)
 
l_ok l_dnaRemoveDupsByAset (L_DNA *das, L_DNA **pdad)
 
l_ok l_dnaUnionByAset (L_DNA *da1, L_DNA *da2, L_DNA **pdad)
 
l_ok l_dnaIntersectionByAset (L_DNA *da1, L_DNA *da2, L_DNA **pdad)
 
L_HASHMAPl_hmapCreateFromDna (L_DNA *da)
 
l_ok l_dnaRemoveDupsByHmap (L_DNA *das, L_DNA **pdad, L_HASHMAP **phmap)
 
l_ok l_dnaUnionByHmap (L_DNA *da1, L_DNA *da2, L_DNA **pdad)
 
l_ok l_dnaIntersectionByHmap (L_DNA *da1, L_DNA *da2, L_DNA **pdad)
 
l_ok l_dnaMakeHistoByHmap (L_DNA *das, L_DNA **pdav, L_DNA **pdac)
 
L_DNAl_dnaDiffAdjValues (L_DNA *das)
 

Detailed Description

     Rearrangements
         l_int32     *l_dnaJoin()
         l_int32     *l_dnaaFlattenToDna()
         L_DNA       *l_dnaSelectRange()
     Conversion between numa and dna
         NUMA        *l_dnaConvertToNuma()
         L_DNA       *numaConvertToDna()
     Conversion from pix data to dna
         L_DNA       *pixConvertDataToDna()
     Set operations using aset (rbtree)
         L_ASET      *l_asetCreateFromDna()
         L_DNA       *l_dnaRemoveDupsByAset()
         L_DNA       *l_dnaUnionByAset()
         L_DNA       *l_dnaIntersectionByAset()
     Hashmap operations
         L_HASHMAP   *l_hmapCreateFromDna()
         l_int32      l_dnaRemoveDupsByHmap()
         l_int32      l_dnaUnionByHmap()
         l_int32      l_dnaIntersectionByHmap()
         l_int32      l_dnaMakeHistoByHmap()
     Miscellaneous operations
         L_DNA       *l_dnaDiffAdjValues()
We have two implementations of set operations on an array of doubles:
  (1) Using an underlying tree (rbtree)
      The key for each float64 value is the value itself.
      No collisions can occur.  The tree is sorted by the keys.
      Lookup is done in O(log n) by traversing from the root,
      looking for the key.
  (2) Building a hashmap from the keys (hashmap)
      The keys are made from each float64 by casting into a uint64.
      The key is then hashed into a hashtable.  Collisions of hashkeys are
      very rare, and the hashtable is designed to allow more than one
      hashitem in a table entry.  The hashitems are put in a list at
      each hashtable entry, which is traversed looking for the key.

Definition in file dnafunc1.c.

Function Documentation

◆ l_asetCreateFromDna()

L_ASET* l_asetCreateFromDna ( L_DNA da)

l_asetCreateFromDna()

Parameters
[in]dasource dna
Returns
set using the doubles in da as keys

Definition at line 332 of file dnafunc1.c.

Referenced by l_dnaIntersectionByAset().

◆ l_dnaaFlattenToDna()

L_DNA* l_dnaaFlattenToDna ( L_DNAA daa)

l_dnaaFlattenToDna()

Parameters
[in]daa
Returns
dad, or NULL on error
Notes:
     (1) This 'flattens' the dnaa to a dna, by joining successively
         each dna in the dnaa.
     (2) It leaves the input dnaa unchanged.

Definition at line 152 of file dnafunc1.c.

References L_Dnaa::dna, l_dnaCreate(), l_dnaJoin(), and L_Dnaa::nalloc.

◆ l_dnaConvertToNuma()

NUMA* l_dnaConvertToNuma ( L_DNA da)

l_dnaConvertToNuma()

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

Definition at line 232 of file dnafunc1.c.

References l_dnaGetCount(), l_dnaGetDValue(), numaAddNumber(), and numaCreate().

◆ l_dnaDiffAdjValues()

L_DNA* l_dnaDiffAdjValues ( L_DNA das)

l_dnaDiffAdjValues()

Parameters
[in]dasinput l_dna
Returns
dad of difference values val[i+1] - val[i], or NULL on error

Definition at line 785 of file dnafunc1.c.

References l_dnaAddNumber(), l_dnaCreate(), l_dnaGetCount(), and l_dnaGetIValue().

◆ l_dnaIntersectionByAset()

l_ok l_dnaIntersectionByAset ( L_DNA da1,
L_DNA da2,
L_DNA **  pdad 
)

l_dnaIntersectionByAset()

Parameters
[in]da1
[in]da2
[out]pdadintersection of the two arrays
Returns
0 if OK; 1 on error
Notes:
     (1) See sarrayIntersection() for the approach.
     (2) Here, the key in building the sorted tree is the number itself.
     (3) Operations using an underlying tree are O(nlogn), which is
         typically less efficient than hashing, which is O(n).

Definition at line 462 of file dnafunc1.c.

References l_asetCreateFromDna(), l_dnaCreate(), and l_dnaGetCount().

◆ l_dnaIntersectionByHmap()

l_ok l_dnaIntersectionByHmap ( L_DNA da1,
L_DNA da2,
L_DNA **  pdad 
)

l_dnaIntersectionByHmap()

Parameters
[in]da1
[in]da2
[out]pdadintersection of the array values
Returns
0 if OK; 1 on error
 Notes:
      (1) Make dna with numbers common to both input arrays.
      (2) Use the values in the dna as the hash keys.

Definition at line 664 of file dnafunc1.c.

References L_Hashitem::count, l_dnaAddNumber(), l_dnaCreate(), l_dnaGetCount(), l_dnaGetDValue(), l_hashFloat64ToUint64(), and l_hmapCreateFromDna().

◆ l_dnaJoin()

l_ok l_dnaJoin ( L_DNA dad,
L_DNA das,
l_int32  istart,
l_int32  iend 
)

l_dnaJoin()

Parameters
[in]daddest dna; add to this one
[in]das[optional] source dna; add from this one
[in]istartstarting index in das
[in]iendending index in das; use -1 to cat all
Returns
0 if OK, 1 on error
Notes:
     (1) istart < 0 is taken to mean 'read from the start' (istart = 0)
     (2) iend < 0 means 'read to the end'
     (3) if das == NULL, this is a no-op

Definition at line 103 of file dnafunc1.c.

References l_dnaAddNumber(), l_dnaGetCount(), and l_dnaGetDValue().

Referenced by l_dnaaFlattenToDna(), l_dnaUnionByAset(), and l_dnaUnionByHmap().

◆ l_dnaMakeHistoByHmap()

l_ok l_dnaMakeHistoByHmap ( L_DNA das,
L_DNA **  pdav,
L_DNA **  pdac 
)

l_dnaMakeHistoByHmap()

Parameters
[in]das
[out]pdavarray (set) of unique values
[out]pdacarray of counts, aligned with the array of values
Returns
0 if OK; 1 on error
 Notes:
      (1) Generates a histogram represented by two aligned arrays:
          value and count.

Definition at line 730 of file dnafunc1.c.

References L_Hashitem::count, L_Hashmap::hashtab, l_dnaAddNumber(), l_dnaCreate(), l_dnaGetDValue(), l_hmapCreateFromDna(), L_Hashitem::next, L_Hashmap::tabsize, and L_Hashitem::val.

◆ l_dnaRemoveDupsByAset()

l_ok l_dnaRemoveDupsByAset ( L_DNA das,
L_DNA **  pdad 
)

l_dnaRemoveDupsByAset()

Parameters
[in]das
[out]pdadwith duplicated removed
Returns
0 if OK; 1 on error

Definition at line 364 of file dnafunc1.c.

Referenced by l_dnaUnionByAset().

◆ l_dnaRemoveDupsByHmap()

l_ok l_dnaRemoveDupsByHmap ( L_DNA das,
L_DNA **  pdad,
L_HASHMAP **  phmap 
)

l_dnaRemoveDupsByHmap()

Parameters
[in]das
[out]pdadhash set of unique values
[out]phmap[optional] hashmap used for lookup
Returns
0 if OK; 1 on error
 Notes:
      (1) Generates the set of (unique) values from das.
      (2) The values in the hashitems are indices into das.

Definition at line 565 of file dnafunc1.c.

References L_Hashmap::hashtab, l_dnaAddNumber(), l_dnaCreate(), l_dnaGetDValue(), l_hmapCreateFromDna(), L_Hashitem::next, L_Hashmap::tabsize, and L_Hashitem::val.

Referenced by l_dnaUnionByHmap().

◆ l_dnaSelectRange()

L_DNA* l_dnaSelectRange ( L_DNA das,
l_int32  first,
l_int32  last 
)

l_dnaSelectRange()

Parameters
[in]das
[in]firstuse 0 to select from the beginning
[in]lastuse -1 to select to the end
Returns
dad, or NULL on error

Definition at line 185 of file dnafunc1.c.

References l_dnaAddNumber(), l_dnaCopy(), l_dnaCreate(), l_dnaGetCount(), and l_dnaGetDValue().

◆ l_dnaUnionByAset()

l_ok l_dnaUnionByAset ( L_DNA da1,
L_DNA da2,
L_DNA **  pdad 
)

l_dnaUnionByAset()

Parameters
[in]da1
[in]da2
[out]pdadunion of the two arrays
Returns
0 if OK; 1 on error
Notes:
     (1) See sarrayUnionByAset() for the approach.
     (2) Here, the key in building the sorted tree is the number itself.
     (3) Operations using an underlying tree are O(nlogn), which is
         typically less efficient than hashing, which is O(n).

Definition at line 416 of file dnafunc1.c.

References l_dnaCopy(), l_dnaDestroy(), l_dnaJoin(), and l_dnaRemoveDupsByAset().

◆ l_dnaUnionByHmap()

l_ok l_dnaUnionByHmap ( L_DNA da1,
L_DNA da2,
L_DNA **  pdad 
)

l_dnaUnionByHmap()

Parameters
[in]da1
[in]da2
[out]pdadunion of the array values
Returns
0 if OK; 1 on error
 Notes:
      (1) Make dna with numbers found in either of the input arrays.

Definition at line 622 of file dnafunc1.c.

References l_dnaCopy(), l_dnaDestroy(), l_dnaJoin(), and l_dnaRemoveDupsByHmap().

◆ l_hmapCreateFromDna()

L_HASHMAP* l_hmapCreateFromDna ( L_DNA da)

l_hmapCreateFromDna()

Parameters
[in]dainput dna
Returns
hmap hashmap, or NULL on error
 Notes:
      (1) Derive the hash keys from the values in da.
      (2) The indices into da are stored in the val field of the hashitems.
          This is necessary so that hmap and da can be used together.

Definition at line 526 of file dnafunc1.c.

References l_dnaGetCount(), l_dnaGetDValue(), and l_hashFloat64ToUint64().

Referenced by l_dnaIntersectionByHmap(), l_dnaMakeHistoByHmap(), and l_dnaRemoveDupsByHmap().

◆ numaConvertToDna()

L_DNA* numaConvertToDna ( NUMA na)

numaConvertToDna

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

Definition at line 260 of file dnafunc1.c.

References l_dnaAddNumber(), l_dnaCreate(), numaGetCount(), and numaGetFValue().

◆ pixConvertDataToDna()

L_DNA* pixConvertDataToDna ( PIX pix)

pixConvertDataToDna()

Parameters
[in]pix32 bpp RGB(A)
Returns
da, or NULL on error
Notes:
     (1) This writes the RGBA pixel values into the dna, in row-major order.

Definition at line 296 of file dnafunc1.c.

References L_Dewarp::h, and L_Dewarp::w.