MCPcopy Create free account
hub / github.com/creatale/node-dv / sarrayRemoveDupsByAset

Function sarrayRemoveDupsByAset

deps/leptonica/src/sarray2.c:276–306  ·  view source on GitHub ↗

! * \brief sarrayRemoveDupsByAset() * * \param[in] sas * \return sad with duplicates removed, or NULL on error * * * Notes: * (1) This is O(nlogn), considerably slower than * sarrayRemoveDupsByHash() for large string arrays. * (2) The key for each string is a 64-bit hash. * (3) Build a set, using hashed strings as keys. As the set is * buil

Source from the content-addressed store, hash-verified

274 * </pre>
275 */
276SARRAY *
277sarrayRemoveDupsByAset(SARRAY *sas)
278{
279char *str;
280l_int32 i, n;
281l_uint64 hash;
282L_ASET *set;
283RB_TYPE key;
284SARRAY *sad;
285
286 PROCNAME("sarrayRemoveDupsByAset");
287
288 if (!sas)
289 return (SARRAY *)ERROR_PTR("sas not defined", procName, NULL);
290
291 set = l_asetCreate(L_UINT_TYPE);
292 sad = sarrayCreate(0);
293 n = sarrayGetCount(sas);
294 for (i = 0; i < n; i++) {
295 str = sarrayGetString(sas, i, L_NOCOPY);
296 l_hashStringToUint64(str, &hash);
297 key.utype = hash;
298 if (!l_asetFind(set, key)) {
299 sarrayAddString(sad, str, L_COPY);
300 l_asetInsert(set, key);
301 }
302 }
303
304 l_asetDestroy(&set);
305 return sad;
306}
307
308
309/*!

Callers 1

sarrayUnionByAsetFunction · 0.85

Calls 9

l_asetCreateFunction · 0.85
sarrayCreateFunction · 0.85
sarrayGetCountFunction · 0.85
sarrayGetStringFunction · 0.85
l_hashStringToUint64Function · 0.85
l_asetFindFunction · 0.85
sarrayAddStringFunction · 0.85
l_asetInsertFunction · 0.85
l_asetDestroyFunction · 0.85

Tested by

no test coverage detected