! * \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
| 274 | * </pre> |
| 275 | */ |
| 276 | SARRAY * |
| 277 | sarrayRemoveDupsByAset(SARRAY *sas) |
| 278 | { |
| 279 | char *str; |
| 280 | l_int32 i, n; |
| 281 | l_uint64 hash; |
| 282 | L_ASET *set; |
| 283 | RB_TYPE key; |
| 284 | SARRAY *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 | /*! |
no test coverage detected