コード例 #1
0
ファイル: util.c プロジェクト: rhennigan/code
void div_tree(bintree_t * bt, FILE * out) {
  list_t * cvecs = bt_get_data(bt);
  int32_t split = split_by(cvecs);
  list_t * cvecs_l = NULL;
  list_t * cvecs_r = NULL;
  list_t * tmp = cvecs;
  while (tmp != NULL) {
    void * addr = list_head(tmp);
    int32_t * cvec = (int32_t*)addr;
    if (cvec[split+1]) {
      cvecs_l = list_cons(cvecs_l, addr);
    } else {
      cvecs_r = list_cons(cvecs_r, addr);
    }
    tmp = list_tail(tmp);
  }

  if (cvecs_l == NULL || cvecs_r == NULL) {
    return;
  }

  bt_insl(bt, cvecs_l);
  bt_insr(bt, cvecs_r);

  void * a1 = bt;
  void * a2 = bt_get_left(bt);
  void * a3 = bt_get_right(bt);

  fprintf(out, "\"%p\"->\"%p\",\n", a1, a2);
  fprintf(out, "\"%p\"->\"%p\",\n", a1, a3);

  div_tree(bt_get_left(bt), out);
  div_tree(bt_get_right(bt), out);
}
コード例 #2
0
ContainerOut split_words_by
        (const typename String::value_type delim,
         const bool allowEmpty, const String& str)
{
    const auto comparator = [delim](const typename String::value_type ch)
    {
        return ch == delim;
    };
    return split_by(comparator, allowEmpty, str);
}
コード例 #3
0
ContainerOut split_words_by_many
        (const String& delims, const bool allowEmpty, const String& str)
{
    typedef typename String::value_type CharType;
    const auto comparator = [&delims](const CharType ch)
    {
        return std::any_of(std::begin(delims), std::end(delims),
                    [ch](const CharType delim) { return ch == delim; });
    };
    return split_by(comparator, allowEmpty, str);
}
コード例 #4
0
 MessageSplitter<InputIterator> split(InputIterator begin, InputIterator end)
 {
     return split_by(begin, end, MessageSplitter<InputIterator>(begin));
 }
コード例 #5
0
ContainerOut split_words(const bool allowEmpty, const String& str)
{
    return split_by(logical_not(is_letter_or_digit<String>), allowEmpty, str);
}
コード例 #6
0
ContainerOut split_lines(bool allowEmpty, const String& str)
{
    return split_by(is_line_break<String>, allowEmpty, clean_newlines(str));
}