コード例 #1
0
ファイル: q94.c プロジェクト: seanxiao2net/InterviewLearning
int main() {
    char set[] = "ABCD";
    int sz = strlen(set);
    char buff[sz+1];

    Subset(set, buff, sz, 0, 0);

    return 0;
}
コード例 #2
0
Subset<T> Subset<T>::MakeSingleton(
    T& element,
    SubsetPropertiesArgs... subset_properties_args) {
  not_null<Node*> node = Node::Get(element);
  node->parent_ = node;
  node->rank_ = 0;
  node->properties_.value = Properties(
      std::forward<SubsetPropertiesArgs>(subset_properties_args)...);
  return Subset(node);
}
コード例 #3
0
ファイル: q94.c プロジェクト: seanxiao2net/InterviewLearning
void Subset(char* set, char* buff,  int sz, int token, int lvl) {
    int i;
    for (i=token; i<sz; ++i) {
        *(buff+lvl) = set[i];
        *(buff+lvl+1) = '\0';
        printf("%s\n", buff);

        if (i<sz-1) Subset(set, buff, sz, i+1, lvl+1);
    }
}
コード例 #4
0
Subset<T> Subset<T>::Unite(Subset left, Subset right) {
  not_null<Node*> const left_root = left.node_;
  not_null<Node*> const right_root = right.node_;
  if (left_root == right_root) {
    return left;
  } else if (left_root->rank_ < right_root->rank_) {
    left_root->parent_ = right_root;
    right_root->properties_.value.MergeWith(left_root->properties_.value);
    return Subset(right_root);
  } else if (right_root->rank_ < left_root->rank_) {
    right_root->parent_ = left_root;
    left_root->properties_.value.MergeWith(right_root->properties_.value);
    return Subset(left_root);
  } else {
    right_root->parent_ = left_root;
    ++left_root->rank_;
    left_root->properties_.value.MergeWith(right_root->properties_.value);
    return Subset(left_root);
  }
}
コード例 #5
0
ファイル: subset_scores.cpp プロジェクト: apolitis/imp
Subset RestraintCache::get_subset(kernel::Restraint *r,
                                  const DepMap &dependencies) const {
  kernel::ParticlesTemp ups = IMP::get_input_particles(r->get_inputs());
  std::sort(ups.begin(), ups.end());
  ups.erase(std::unique(ups.begin(), ups.end()), ups.end());
  kernel::ParticlesTemp outps;
  for (unsigned int i = 0; i < ups.size(); ++i) {
    DepMap::const_iterator it = dependencies.find(ups[i]);
    if (it != dependencies.end()) {
      outps = outps + it->second;
    }
  }
  std::sort(outps.begin(), outps.end());
  outps.erase(std::unique(outps.begin(), outps.end()), outps.end());
  return Subset(outps);
}
コード例 #6
0
ファイル: subset_scores.cpp プロジェクト: apolitis/imp
void RestraintCache::add_restraint_set_internal(kernel::RestraintSet *rs,
                                                unsigned int index,
                                                const Subset &cur_subset,
                                                double cur_max,
                                                const DepMap &dependencies) {
  IMP_LOG_TERSE("Parsing restraint set " << Showable(rs) << std::endl);
  if (cur_max < std::numeric_limits<double>::max()) {
    for (kernel::RestraintSet::RestraintIterator it = rs->restraints_begin();
         it != rs->restraints_end(); ++it) {
      add_restraint_internal(*it, index, rs, cur_max, cur_subset, dependencies);
    }
  } else {
    for (kernel::RestraintSet::RestraintIterator it = rs->restraints_begin();
         it != rs->restraints_end(); ++it) {
      add_restraint_internal(*it, index, nullptr,
                             std::numeric_limits<double>::max(), Subset(),
                             dependencies);
    }
  }
}
コード例 #7
0
ファイル: subset_scores.cpp プロジェクト: apolitis/imp
void RestraintCache::add_restraints(const kernel::RestraintsAdaptor &rs) {
  IMP_OBJECT_LOG;
  if (rs.empty()) return;
  kernel::Model *m = rs[0]->get_model();
  DependencyGraph dg = get_dependency_graph(m);
  ParticleStatesTable *pst = cache_.get_generator().get_particle_states_table();
  DepMap dependencies;
  kernel::ParticlesTemp allps = pst->get_particles();
  DependencyGraphVertexIndex index = IMP::get_vertex_index(dg);
  for (unsigned int i = 0; i < allps.size(); ++i) {
    kernel::ParticlesTemp depp =
        get_dependent_particles(allps[i], allps, dg, index);
    for (unsigned int j = 0; j < depp.size(); ++j) {
      dependencies[depp[j]].push_back(allps[i]);
    }
    dependencies[allps[i]].push_back(allps[i]);
    IMP_LOG_TERSE("Particle " << Showable(allps[i]) << " controls "
                              << dependencies[allps[i]] << std::endl);
  }

  for (unsigned int i = 0; i < rs.size(); ++i) {
    base::Pointer<kernel::Restraint> r = rs[i]->create_decomposition();
    IMP_IF_LOG(TERSE) {
      IMP_LOG_TERSE("Before:" << std::endl);
      IMP_LOG_WRITE(TERSE, show_restraint_hierarchy(rs[i]));
    }
    if (r) {
      IMP_LOG_TERSE("after:" << std::endl);
      IMP_LOG_WRITE(TERSE, show_restraint_hierarchy(r));
      add_restraint_internal(r, next_index_, nullptr,
                             std::numeric_limits<double>::max(), Subset(),
                             dependencies);
    }
    ++next_index_;
  }
  IMP_IF_LOG(TERSE) {
    IMP_LOG_WRITE(TERSE, show_restraint_information(IMP_STREAM));
  }
}
コード例 #8
0
Subset<T> Subset<T>::Find(T& element) {
  return Subset(Node::Get(element)->Root());
}
コード例 #9
0
r_Ref<r_GMarray>& RasdamanDataset::request_array(int x_lo, int x_hi, int y_lo, int y_hi, int& offsetX, int& offsetY)
{
  return request_array(Subset(x_lo, x_hi, y_lo, y_hi), offsetX, offsetY);
};