| 684 | } |
| 685 | |
| 686 | void SIValue_HashUpdate(SIValue v, XXH64_state_t *state) { |
| 687 | // handles null value and defaults |
| 688 | int64_t null = 0; |
| 689 | XXH64_hash_t inner_hash; |
| 690 | // in case of identical binary representation of the value, |
| 691 | // we should hash the type as well |
| 692 | SIType t = SI_TYPE(v); |
| 693 | |
| 694 | switch(t) { |
| 695 | case T_NULL: |
| 696 | XXH64_update(state, &t, sizeof(t)); |
| 697 | XXH64_update(state, &null, sizeof(null)); |
| 698 | return; |
| 699 | case T_STRING: |
| 700 | XXH64_update(state, &t, sizeof(t)); |
| 701 | XXH64_update(state, v.stringval, strlen(v.stringval)); |
| 702 | return; |
| 703 | case T_INT64: |
| 704 | // change type to numeric |
| 705 | t = SI_NUMERIC; |
| 706 | XXH64_update(state, &t, sizeof(t)); |
| 707 | XXH64_update(state, &v.longval, sizeof(v.longval)); |
| 708 | return; |
| 709 | case T_BOOL: |
| 710 | XXH64_update(state, &t, sizeof(t)); |
| 711 | XXH64_update(state, &v.longval, sizeof(v.longval)); |
| 712 | return; |
| 713 | case T_DOUBLE: |
| 714 | t = SI_NUMERIC; |
| 715 | XXH64_update(state, &t, sizeof(t)); |
| 716 | // check if the double value is actually an integer |
| 717 | // if so, hash it as Long |
| 718 | int64_t casted = (int64_t) v.doubleval; |
| 719 | double diff = v.doubleval - casted; |
| 720 | if(diff != 0) XXH64_update(state, &v.doubleval, sizeof(v.doubleval)); |
| 721 | else XXH64_update(state, &casted, sizeof(casted)); |
| 722 | return; |
| 723 | case T_EDGE: |
| 724 | inner_hash = SIEdge_HashCode(v); |
| 725 | XXH64_update(state, &inner_hash, sizeof(inner_hash)); |
| 726 | return; |
| 727 | case T_NODE: |
| 728 | inner_hash = SINode_HashCode(v); |
| 729 | XXH64_update(state, &inner_hash, sizeof(inner_hash)); |
| 730 | return; |
| 731 | case T_ARRAY: |
| 732 | inner_hash = SIArray_HashCode(v); |
| 733 | XXH64_update(state, &inner_hash, sizeof(inner_hash)); |
| 734 | return; |
| 735 | case T_MAP: |
| 736 | inner_hash = Map_HashCode(v); |
| 737 | XXH64_update(state, &inner_hash, sizeof(inner_hash)); |
| 738 | return; |
| 739 | case T_PATH: |
| 740 | inner_hash = SIPath_HashCode(v); |
| 741 | XXH64_update(state, &inner_hash, sizeof(inner_hash)); |
| 742 | return; |
| 743 | // TODO: Implement for temporal types once we support them. |
no test coverage detected