/ AddDistinctValue: Check whether this value already exist in the */ list and if not add it to the distinct values list. */ /
| 2882 | /* list and if not add it to the distinct values list. */ |
| 2883 | /***********************************************************************/ |
| 2884 | bool DOSCOL::AddDistinctValue(PGLOBAL g) |
| 2885 | { |
| 2886 | bool found = false; |
| 2887 | int i, m, n; |
| 2888 | |
| 2889 | ReadColumn(g); // Extract column value from current line |
| 2890 | |
| 2891 | // Perhaps a better algorithm can be used when Ndv gets bigger |
| 2892 | // Here we cannot use Find because we must get the index of where |
| 2893 | // to insert a new value if it is not found in the array. |
| 2894 | for (n = 0; n < Ndv; n++) { |
| 2895 | m = Dval->CompVal(Value, n); |
| 2896 | |
| 2897 | if (m > 0) |
| 2898 | continue; |
| 2899 | else if (!m) |
| 2900 | found = true; // Already there |
| 2901 | |
| 2902 | break; |
| 2903 | } // endfor n |
| 2904 | |
| 2905 | if (!found) { |
| 2906 | // Check whether we have room for an additional value |
| 2907 | if (Ndv == Freq) { |
| 2908 | // Too many values because of wrong Freq setting |
| 2909 | snprintf(g->Message, sizeof(g->Message), MSG(BAD_FREQ_SET), Name); |
| 2910 | return true; |
| 2911 | } // endif Ndv |
| 2912 | |
| 2913 | // New value, add it to the list before the nth value |
| 2914 | Dval->SetNval(Ndv + 1); |
| 2915 | |
| 2916 | for (i = Ndv; i > n; i--) |
| 2917 | Dval->Move(i - 1, i); |
| 2918 | |
| 2919 | Dval->SetValue(Value, n); |
| 2920 | Ndv++; |
| 2921 | } // endif found |
| 2922 | |
| 2923 | return false; |
| 2924 | } // end of AddDistinctValue |
| 2925 | |
| 2926 | /* ------------------------------------------------------------------- */ |
no test coverage detected