示例#1
0
  void intersect(const svector<F,V>& y, Op& op) const {
    // can't do bounded search with std::map, otherwise we would do double binary search
    // these thresholds have not been well optimized
    if (m.size() < 0.1*y.size()) {
      for (const_iterator xit=m.begin(); xit != m.end(); ++xit) {
	const_iterator yit = y.find(xit->first);
	if (yit != y.end())
	  op(xit->first, xit->second, yit->second);
      }
    } else if (0.1*m.size() > y.size()) {
      for (const_iterator yit=y.begin(); yit != y.end(); ++yit) {
	const_iterator xit = m.find(yit->first);
	if (xit != m.end())
	  op(yit->first, xit->second, yit->second);
      }
    } else {
      const_iterator xit = m.begin();
      const_iterator yit = y.begin();
      while (xit != m.end() && yit != y.end()) {
	if (xit->first > yit->first) {
	  ++yit;
	} else if (xit->first < yit->first) {
	  ++xit;
	} else {
	  op(xit->first, xit->second, yit->second);
	  ++xit; ++yit;
	}
      }
    }
  }
示例#2
0
 virtual void execute(cmd_context & ctx) {
     ctx.regular_stream() << "\"";
     if (m_cmds.empty()) {
         vector<named_cmd> cmds;
         cmd_context::cmd_iterator it  = ctx.begin_cmds();
         cmd_context::cmd_iterator end = ctx.end_cmds();
         for (; it != end; ++it) {
             cmds.push_back(named_cmd((*it).m_key, (*it).m_value));
         }
         // named_cmd_lt is not a total order for commands, but this is irrelevant for Linux x Windows behavior
         std::sort(cmds.begin(), cmds.end(), named_cmd_lt());
         vector<named_cmd>::const_iterator it2  = cmds.begin();
         vector<named_cmd>::const_iterator end2 = cmds.end();
         for (; it2 != end2; ++it2) {
             display_cmd(ctx, it2->first, it2->second);
         }
     }
     else {
         svector<symbol>::const_iterator it  = m_cmds.begin();
         svector<symbol>::const_iterator end = m_cmds.end();
         for (; it != end; ++it) {
             cmd * c = ctx.find_cmd(*it);
             SASSERT(c);
             display_cmd(ctx, *it, c);
         }
     }
     ctx.regular_stream() << "\"\n";
 }
示例#3
0
 void display(std::ostream & out, symbol const & k) const {
     svector<params::entry>::const_iterator it  = m_entries.begin();  
     svector<params::entry>::const_iterator end = m_entries.end();
     for (; it != end; ++it) {                                
         if (it->first != k)
             continue;
         switch (it->second.m_kind) {
         case CPK_BOOL:
             out << (it->second.m_bool_value?"true":"false");
             return;
         case CPK_UINT:
             out << it->second.m_uint_value;
             return;
         case CPK_DOUBLE:
             out << it->second.m_double_value;
             return;
         case CPK_NUMERAL:
             out << *(it->second.m_rat_value);
             return;
         case CPK_SYMBOL:
             out << symbol::mk_symbol_from_c_ptr(it->second.m_sym_value);
             return;
         case CPK_STRING:
             out << it->second.m_str_value;
             return;
         default:
             out << "internal";
             return;
         }
     }
     out << "default";
 }
示例#4
0
 void display_smt2(std::ostream & out, char const* module, param_descrs& descrs) const {
     svector<params::entry>::const_iterator it  = m_entries.begin();  
     svector<params::entry>::const_iterator end = m_entries.end();
     for (; it != end; ++it) {
         if (!descrs.contains(it->first)) continue;
         out << "(set-option :";
         out << module << ".";        
         out << it->first;
         switch (it->second.m_kind) {
         case CPK_BOOL:
             out << " " << (it->second.m_bool_value?"true":"false");
             break;
         case CPK_UINT:
             out << " " <<it->second.m_uint_value;
             break;
         case CPK_DOUBLE:
             out << " " << it->second.m_double_value;
             break;
         case CPK_NUMERAL:
             out << " " << *(it->second.m_rat_value);
             break;
         case CPK_SYMBOL:
             out << " " << symbol::mk_symbol_from_c_ptr(it->second.m_sym_value);
             break;
         case CPK_STRING:
             out << " " << it->second.m_str_value;
             break;
         default:
             UNREACHABLE();
             break;
         }
         out << ")\n";
     }
 }
示例#5
0
 void display(std::ostream & out) const {
     out << "(params";
     svector<params::entry>::const_iterator it  = m_entries.begin();  
     svector<params::entry>::const_iterator end = m_entries.end();
     for (; it != end; ++it) {
         out << " " << it->first;            
         switch (it->second.m_kind) {
         case CPK_BOOL:
             out << " " << (it->second.m_bool_value?"true":"false");
             break;
         case CPK_UINT:
             out << " " <<it->second.m_uint_value;
             break;
         case CPK_DOUBLE:
             out << " " << it->second.m_double_value;
             break;
         case CPK_NUMERAL:
             out << " " << *(it->second.m_rat_value);
             break;
         case CPK_SYMBOL:
             out << " " << symbol::mk_symbol_from_c_ptr(it->second.m_sym_value);
             break;
         case CPK_STRING:
             out << " " << it->second.m_str_value;
             break;
         default:
             UNREACHABLE();
             break;
         }
     }
     out << ")";
 }
示例#6
0
 void refill_buffer(unsigned start) {
     unsigned should_read = m_data_size-start;
     m_stm.read(m_data.begin()+start, should_read);
     unsigned actually_read = static_cast<unsigned>(m_stm.gcount());
     SASSERT(should_read==actually_read || m_stm.eof());
     if(m_stm.eof()) {
         m_eof_behind_buffer = true;
         resize_data(start+actually_read);
     }
 }
示例#7
0
 void validate(param_descrs const & p) const {
     svector<params::entry>::const_iterator it  = m_entries.begin();  
     svector<params::entry>::const_iterator end = m_entries.end();
     for (; it != end; ++it) {                                
         param_kind expected = p.get_kind(it->first);
         if (expected == CPK_INVALID)
             throw default_exception("unknown parameter '%s'", it->first.str().c_str());
         if (it->second.m_kind != expected) 
             throw default_exception("parameter kind mismatch '%s'", it->first.str().c_str());
     }
 }
示例#8
0
 void refill_buffer(unsigned start) {
     unsigned should_read = m_data_size-start;
     size_t actually_read = fread(m_data.begin()+start, 1, should_read, m_file);
     if(actually_read==should_read) {
         return;
     }
     SASSERT(actually_read < should_read);
     SASSERT(feof(m_file));
     m_eof_behind_buffer = true;
     resize_data(start+static_cast<unsigned>(actually_read));
 }
示例#9
0
    /**
       \brief Retrieve next line from the stream.

       This operation invalidates the line previously retrieved.

       This operatio can be called only if we are not at the end of file.

       User is free to modify the content of the returned array until the terminating NULL character.
     */
    char * get_line() {
        SASSERT(!m_eof);
        unsigned start = m_next_index;
        unsigned curr = start;
        for(;;) {
            SASSERT(curr<=m_data_size);
            SASSERT(m_data[m_data_size]==s_delimiter);
            {
                const char * data_ptr = m_data.begin();
                const char * ptr = data_ptr+curr;
                while(*ptr!=s_delimiter) {
                    ptr++;
                }
                curr = static_cast<unsigned>(ptr-data_ptr);
            }
            SASSERT(m_data[curr]==s_delimiter);
            if(curr<m_data_size || m_eof_behind_buffer) {
                if(curr==m_data_size) {
                    SASSERT(m_eof_behind_buffer);
                    m_eof = true;
                }
                m_data[curr] = 0; //put in string terminator
                m_next_index = curr+1;
                return m_data.begin()+start;
            }
            if(start!=0) {
                unsigned len = curr-start;
                if(len) {
                    memmove(m_data.begin(), m_data.begin()+start, len);
                }
                start = 0;
                curr = len;
            }
            if(m_data_size-curr<s_expansion_step) {
                resize_data(m_data_size+s_expansion_step);
            }
            refill_buffer(curr);
        }
    }
示例#10
0
文件: utils.cpp 项目: kindex/Steel
// concat array of string into one string
std::string implode(const char delimiter, const svector<std::string>& elements)
{
	if (elements.empty())
	{
		return "";
	}

	std::string res;
	svector<string>::const_iterator it = elements.begin();
	res = *it;
	it++;
	for(; it != elements.end(); it++)
	{
		res += delimiter;
		res += *it;
	}
	return res;
}
示例#11
0
 void validate(param_descrs const & p) {
     svector<params::entry>::iterator it  = m_entries.begin();  
     svector<params::entry>::iterator end = m_entries.end();
     symbol suffix, prefix;
     for (; it != end; ++it) {                                
         param_kind expected = p.get_kind_in_module(it->first);
         if (expected == CPK_INVALID) {
             std::stringstream strm;
             strm << "unknown parameter '" << it->first.str() << "'\n";    
             strm << "Legal parameters are:\n";
             p.display(strm, 2, false, false);
             throw default_exception(strm.str());
         }
         if (it->second.m_kind != expected && 
             !(it->second.m_kind == CPK_UINT && expected == CPK_NUMERAL)) {
             std::stringstream strm;
             strm << "Parameter " << it->first.str() << " was given argument of type ";
             strm << it->second.m_kind << ", expected " << expected;                
             throw default_exception(strm.str());
         }
     }
 }