MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / AR_DEDUP

Function AR_DEDUP

src/arithmetic/list_funcs/list_funcs.c:662–694  ·  view source on GitHub ↗

given a list, return a similar list after removing duplicate elements order is preserved, duplicates are removed from the end of the list list.dedup(list) -> list list.dedup([1,2,1,3,3]) -> [1,2,3]

Source from the content-addressed store, hash-verified

660// list.dedup(list) -> list
661// list.dedup([1,2,1,3,3]) -> [1,2,3]
662SIValue AR_DEDUP(SIValue *argv, int argc, void *private_data) {
663 SIValue list = argv[0];
664 if(SI_TYPE(list) == T_NULL) {
665 return SI_NullVal();
666 }
667
668 uint32_t n = SIArray_Length(list);
669 SIValue dedup_list = SI_Array(n);
670
671 dict *values = HashTableCreate(&def_dt);
672 // check if value already exists in list
673 for(uint i = 0; i < n; i++) {
674 SIValue val = SIArray_Get(list, i);
675 // initialize the hash state
676 XXH64_state_t state;
677 XXH_errorcode res = XXH64_reset(&state, 0);
678 ASSERT(res != XXH_ERROR);
679
680 SIValue_HashUpdate(val, &state);
681
682 // finalize the hash
683 XXH64_hash_t hash = XXH64_digest(&state);
684 dictEntry *existing;
685 dictEntry *entry = HashTableAddRaw(values, (void *)hash, &existing);
686 if(existing == NULL) {
687 SIArray_Append(&dedup_list, val);
688 }
689 }
690
691 HashTableRelease(values);
692
693 return dedup_list;
694}
695
696SIValue AR_REDUCE
697(

Callers 1

AR_INSERTLISTELEMENTSFunction · 0.85

Calls 9

SI_NullValFunction · 0.85
SIArray_LengthFunction · 0.85
SI_ArrayFunction · 0.85
HashTableCreateFunction · 0.85
SIArray_GetFunction · 0.85
SIValue_HashUpdateFunction · 0.85
HashTableAddRawFunction · 0.85
SIArray_AppendFunction · 0.85
HashTableReleaseFunction · 0.85

Tested by

no test coverage detected