Example #1
0
File: main.cpp Project: CCJY/coliru
		static void call_(Iter first, std::true_type)
		{
			oddeven_merge<lo    , hi, step>{}(first);
			oddeven_merge<lo + r, hi, step>{}(first);

			for (std::size_t i = lo + r; i <= hi - r; i += step)
				compare_swap(first[i], first[i+r]);
		}
Example #2
0
static void sort_times() {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "sort_times...");
  
  // Determine if any of the first 4 offsets is local time,
  // if so then we can take 5 TZs as one will be local time.
  int usable_tz = 4;
  for (int i = 0; i < DISPLAY_SIZE; i++) {
    if (0 == s_offset[i]) {
      // Found a local time, so we can use the first 5 configured TZs
      usable_tz = 5;
      break;
    }
  }
    
  // Initialise indexes to unsorted offsets.
  int indexes[CONFIG_SIZE];
  for (int i = 0; i < CONFIG_SIZE; i++) {
    indexes[i] = i;
  }
  
  // Bubblesort offsets via indexes.
  for (int i = 0; i < (usable_tz - 1); i++) {
    for (int j = 0; j < (usable_tz - 1 - i); j++) {
      compare_swap(indexes, j);
    }
  }
  
  // Iterate offsets (via indexes), inserting local time (replacing a TZ if needed).
  bool found_local = false;
  int d = 0;
  for (int i = 0; i < usable_tz; i++) {
    int offset = s_offset[indexes[i]];
    if (OFFSET_NO_DISPLAY == offset) {
      APP_LOG(APP_LOG_LEVEL_DEBUG, "NO DISPLAY");
      break;
    }
    
    if (0 == offset) {
      if (found_local) {
        // Already found a local, so skip this one
        APP_LOG(APP_LOG_LEVEL_DEBUG, "Already found local");
        continue;
      }
      
      // This is the local time...
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Found local");
      s_display[d++] = DISPLAY_LOCAL_TIME;
      found_local = true;
      continue;
    }
    
    if (!found_local && offset < 0) {
      APP_LOG(APP_LOG_LEVEL_DEBUG, "Missed local, adding");
      // We have moved past local time without finding it, so add it in.
      s_display[d++] = DISPLAY_LOCAL_TIME;
      found_local = true;
      // Fall through to add the current TZ
    }
    
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Adding %d", indexes[i]);
    s_display[d++] = indexes[i];
  }
  
  if (!found_local) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Missed local altogether, adding");
    // We did not find or insert a local time in the list at all, so add it last.
    s_display[d++] = DISPLAY_LOCAL_TIME;
    found_local = true;
  }
  
  s_num_display = d;

  for (int i = 0; i < s_num_display; i++) {
    int x = s_display[i];
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Ordered list %d: %s (%ld)",
              i,
              (x == DISPLAY_LOCAL_TIME) ? "LOCAL" : s_tz[x],
              (x == DISPLAY_LOCAL_TIME) ? 0 : s_offset[x]);
  }
  
  create_layers();

  // ----- Handle popup display ------

  // Initialise indexes to unsorted offsets.
  int pindexes[CONFIG_SIZE];
  for (int i = 0; i < CONFIG_SIZE; i++) {
    pindexes[i] = i;
  }
  
  // Bubblesort offsets via indexes.
  for (int i = 0; i < (CONFIG_SIZE - 1); i++) {
    for (int j = 0; j < (CONFIG_SIZE - 1 - i); j++) {
      compare_swap(pindexes, j);
    }
  }
  
  for (int i = 0; i < CONFIG_SIZE; i++) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Popup: %d", pindexes[i]);
    s_p_display[i] = pindexes[i];
  }
  
  create_popup_layers();
  
  APP_LOG(APP_LOG_LEVEL_DEBUG, "...sort_times");
}
Example #3
0
void test_compare_swap() {

    compare_swap();
}
Example #4
0
File: main.cpp Project: CCJY/coliru
		static void call_(Iter first, std::false_type)
		{
			compare_swap(first[lo], first[lo+r]);
		}