the mining function, it is called when mining table is ready @param Mithril the cache struct */
| 921 | @param Mithril the cache struct |
| 922 | */ |
| 923 | static void _Mithril_mining(cache_t *cache) { |
| 924 | Mithril_params_t *Mithril_params = |
| 925 | (Mithril_params_t *)(cache->prefetcher->params); |
| 926 | rec_mining_t *rmtable = Mithril_params->rmtable; |
| 927 | |
| 928 | #ifdef PROFILING |
| 929 | GTimer *timer = g_timer_new(); |
| 930 | gulong microsecond; |
| 931 | g_timer_start(timer); |
| 932 | #endif |
| 933 | |
| 934 | int i, j, k; |
| 935 | |
| 936 | /* first sort mining table, then do the mining */ |
| 937 | /* first remove all elements from hashtable, otherwise after sort, it will |
| 938 | mess up for obj_id_type l but we can't do this for dataType c, otherwise |
| 939 | the string will be freed during remove in hashtable |
| 940 | */ |
| 941 | gint64 *item = (gint64 *)rmtable->mining_table->data; |
| 942 | for (i = 0; i < (int)rmtable->mining_table->len; i++) { |
| 943 | g_hash_table_remove(rmtable->hashtable, GINT_TO_POINTER(*item)); |
| 944 | item += rmtable->mtable_row_len; |
| 945 | } |
| 946 | |
| 947 | g_array_sort(rmtable->mining_table, mining_table_entry_cmp); |
| 948 | |
| 949 | gboolean associated_flag, first_flag; |
| 950 | gint64 *item1, *item2; |
| 951 | gint num_of_ts1, num_of_ts2, shorter_length; |
| 952 | for (i = 0; i < (long)rmtable->mining_table->len - 1; i++) { |
| 953 | item1 = GET_ROW_IN_MTABLE(Mithril_params, i); |
| 954 | num_of_ts1 = _Mithril_get_total_num_of_ts(item1, rmtable->mtable_row_len); |
| 955 | first_flag = TRUE; |
| 956 | |
| 957 | for (j = i + 1; j < (long)rmtable->mining_table->len; j++) { |
| 958 | item2 = GET_ROW_IN_MTABLE(Mithril_params, j); |
| 959 | |
| 960 | // check first timestamp |
| 961 | if (GET_NTH_TS(item2, 1) - GET_NTH_TS(item1, 1) > |
| 962 | Mithril_params->lookahead_range) { |
| 963 | break; |
| 964 | } |
| 965 | num_of_ts2 = _Mithril_get_total_num_of_ts(item2, rmtable->mtable_row_len); |
| 966 | |
| 967 | if (ABS(num_of_ts1 - num_of_ts2) > Mithril_params->confidence) { |
| 968 | continue; |
| 969 | } |
| 970 | |
| 971 | shorter_length = MIN(num_of_ts1, num_of_ts2); |
| 972 | |
| 973 | associated_flag = FALSE; |
| 974 | if (first_flag) { |
| 975 | associated_flag = TRUE; |
| 976 | first_flag = FALSE; |
| 977 | } |
| 978 | // is next line useless?? |
| 979 | if (shorter_length == 1 && |
| 980 | ABS(GET_NTH_TS(item1, 1) - GET_NTH_TS(item2, 1)) == 1) { |
no test coverage detected