Exemplo n.º 1
0
    TEST(Algorithm, IsUnique)
    {
        std::vector<int> a{11, 22, 11};
        EXPECT_FALSE(is_unique(begin(a), end(a)));

        std::vector<int> b{11, 22, 33};
        EXPECT_TRUE(is_unique(begin(b), end(b)));
    }
Exemplo n.º 2
0
char *intersect(char *s1, char *s2){
  int size1=0;
  int size2=0;
  int size;
  while(*s1!='\0'){
    s1++;
    size1++;
  }
  s1-=size1;
  while(*s2!='\0'){
    s2++;
    size2++;
  }
  s2-=size2;
  if(size1>size2)
    size=size1;
  else
    size=size2;

  char *intersect = (char*) malloc(size+1);
  if(intersect==NULL)
    return NULL;

  char *c;
  c=intersect;
  while(*s1!='\0'){
    if(!(is_unique(s2,*s1))){
	*c=*s1;
	c++;
      }
      s1++;
  }
    *c = '\0';
    return intersect;
}
Exemplo n.º 3
0
int udu_utistime( char *dimname, char *unitstr )
{
	int		ierr;
	static int	have_initted=0;
	ut_unit		*unit;
	static ut_unit	*time_unit_with_origin;

	if( (unitstr == NULL) || (!valid_udunits_pkg))
		return(0);

	if( (unit = ut_parse( unitsys, unitstr, UT_ASCII)) == NULL ) {
		/* can't parse unit spec */
		if( is_unique(unitstr) ) 
			fprintf( stderr, "Note: udunits: unknown units for %s: \"%s\"\n",
				dimname, unitstr );
		return( 0 );
		}

	if(!have_initted) {
		if( (time_unit_with_origin = ut_parse( unitsys, "seconds since 1901-01-01", UT_ASCII)) == NULL ) {
			fprintf( stderr, "Internal error: could not ut_parse time origin test string\n" );
			valid_udunits_pkg = 0;
			return(0);
			}
		have_initted = 1;
		}

	ierr = ut_are_convertible( unit, time_unit_with_origin );
	ut_free( unit );

	return( ierr != 0 );   /* Oddly, returns a non-zero number if ARE convertible */
}
Exemplo n.º 4
0
void AbstractQoreNode::deref(ExceptionSink* xsink) {
   //QORE_TRACE("AbstractQoreNode::deref()");
#ifdef DEBUG
#if TRACK_REFS
   if (type == NT_OBJECT)
      printd(REF_LVL, "QoreObject::deref() %p class: %s (%d->%d) %d\n", this, ((QoreObject*)this)->getClassName(), references, references - 1, custom_reference_handlers);
   else
      printd(REF_LVL, "AbstractQoreNode::deref() %p type: %d %s (%d->%d)\n", this, type, getTypeName(), references, references - 1);

#endif
   if (references > 10000000 || references <= 0){
      if (type == NT_STRING)
	 printd(0, "AbstractQoreNode::deref() WARNING, node %p references: %d (type: %s) (val=\"%s\")\n",
		this, references, getTypeName(), ((QoreStringNode*)this)->getBuffer());
      else
	 printd(0, "AbstractQoreNode::deref() WARNING, node %p references: %d (type: %s)\n", this, references, getTypeName());
      assert(false);
   }
#endif
   assert(references > 0);

   if (there_can_be_only_one) {
      assert(is_unique());
      return;
   }

   if (custom_reference_handlers) {
      customDeref(xsink);
   }
   else if (ROdereference()) {
      if (type < NUM_SIMPLE_TYPES || derefImpl(xsink))
	 delete this;
   }
}
Exemplo n.º 5
0
void dump_objects(inv_t *i)
{
    obj_t *o;
    int j;

    if(!i) {
        dsprintf("No objects here!");
        return;
    }

    for(j = 0; j < 52; j++) {
        o = i->object[j];
        if(o) {
            dsprintf("\n");
            dsprintf("OID:      %d\tBasename: %s\tType:     %s", o->oid, o->basename, otypestrings[o->type]);
            if(o->type == OT_GOLD)
                dsprintf("Amount:   %d\n", o->quantity);
            if(is_armor(o))
                dsprintf("AC:       %d\n", o->ac);
            dsprintf("Attack modifier:%s%d\n", (o->attackmod >= 0 ? " +" : " "), o->attackmod);
            dsprintf("Damage modifier:%s%d\n", (o->damagemod >= 0 ? " +" : " "), o->damagemod);
            dsprintf("Unique:   %s\n", is_unique(o) ? "yes" : "no");
            if(is_weapon(o))
                dsprintf("Damage:   %dd%d\n", o->dice, o->sides);

            dsprintf("\n");
        }
    }

}
Exemplo n.º 6
0
void Connection::connect(const std::string& host, uint16 port, const std::function<void()>& connectCallback)
{
    m_connected = false;
    m_connecting = true;
    m_error.clear();
    m_connectCallback = connectCallback;

    asio::ip::tcp::resolver::query query(host, stdext::unsafe_cast<std::string>(port));

    auto self = asConnection();
    m_resolver.async_resolve(query, [=](const boost::system::error_code& error, asio::ip::tcp::resolver::iterator endpointIterator) {
        if(self.is_unique())
            return;
        m_readTimer.cancel();

        if(!error) {
            m_socket.async_connect(*endpointIterator, std::bind(&Connection::onConnect, asConnection(), std::placeholders::_1));

            m_readTimer.expires_from_now(boost::posix_time::seconds(READ_TIMEOUT));
            m_readTimer.async_wait(std::bind(&Connection::onTimeout, asConnection(), std::placeholders::_1));
        } else
            handleError(error);
    });

    m_readTimer.expires_from_now(boost::posix_time::seconds(READ_TIMEOUT));
    m_readTimer.async_wait(std::bind(&Connection::onTimeout, asConnection(), std::placeholders::_1));
}
Exemplo n.º 7
0
void Connection::write(uint8* buffer, uint16 size)
{
    if(!m_connected)
        return;

    // send old buffer if we can't add more data
    if(m_sendBufferSize + size >= SEND_BUFFER_SIZE && m_sendEvent)
        m_sendEvent->execute();

    // we can't send the data right away, otherwise we could create tcp congestion
    memcpy(m_sendBuffer + m_sendBufferSize, buffer, size);
    m_sendBufferSize += size;

    if(!m_sendEvent || m_sendEvent->isExecuted() || m_sendEvent->isCanceled()) {
        auto self = asConnection();

        // wait 1 ms to do the real send
        m_sendEvent = g_dispatcher.scheduleEvent([=] {
            if(self.is_unique())
                return;
            //m_writeTimer.cancel();

            asio::async_write(m_socket,
                              asio::buffer(m_sendBuffer, m_sendBufferSize),
                              std::bind(&Connection::onWrite, asConnection(), std::placeholders::_1, std::placeholders::_2));

            m_writeTimer.expires_from_now(boost::posix_time::seconds(WRITE_TIMEOUT));
            m_writeTimer.async_wait(std::bind(&Connection::onTimeout, asConnection(), std::placeholders::_1));

            m_sendBufferSize = 0;
        }, SEND_INTERVAL);
    }
}
Exemplo n.º 8
0
void SimpleQoreNode::deref() {
   if (there_can_be_only_one) {
      assert(is_unique());
      return;
   }

   if (ROdereference())
      delete this;
}
Exemplo n.º 9
0
/*
 * is_finished: return 1 if no empty grid exist in 
 * puzzle[][9] and all grid is unique. return 0 if not.
 */
int is_finished(int puzzle[][9])
{
	int r, c;

	for (r=0; r<9; r++)
		for (c=0; c<9; c++)
			if (!(is_filled(puzzle, r+1, c+1) || is_unique(r+1, c+1, puzzle)))
				return 0;
	return 1;
}
Exemplo n.º 10
0
bool 
RTTaskFactory::validate() const
{

  if (!m_task.has_start() || !m_task.has_finish()) {
    return false;
  }
  if (!is_unique())
    return false;

  // unknown task...
  return true;
}
Exemplo n.º 11
0
bool
AbstractTaskFactory::TestFAITriangle()
{
  if (!is_unique())
    return false;

  if (m_task.TaskSize() != 4)
    return false;

  const fixed d1 = m_task.getTaskPoint(1)->GetVectorPlanned().Distance;
  const fixed d2 = m_task.getTaskPoint(2)->GetVectorPlanned().Distance;
  const fixed d3 = m_task.getTaskPoint(3)->GetVectorPlanned().Distance;

  return TestFAITriangle(d1, d2, d3);
}
Exemplo n.º 12
0
static apt_bool_t string_table_key_generate(apt_str_table_item_t table[], apr_size_t count)
{
	size_t i,j;
	size_t length;
	for(i=0; i<count; i++) {
		length = table[i].value.length;
		table[i].key = length;
		for(j=0; j<length; j++) {
			if(is_unique(table,count,i,j,table[i].value.buf[j]) == TRUE) {
				table[i].key = j;
				break;
			}
		}
	}
	return TRUE;
}
Exemplo n.º 13
0
bool 
FAITaskFactory::validate() const
{

  if (!m_task.has_start() || !m_task.has_finish()) {
    return false;
  }

  if ((m_task.task_size()>2) && (!is_closed()))
    return false;

  if (!is_unique())
    return false;

  return true;
}
Exemplo n.º 14
0
int main(int argc, char *argv[])
{
  if (argc != 2)
    perror("input the correct command and its parameters");
    
  if (is_unique(argv[1]))
  {
    printf("every chars are unique from the string.\n");
  }
  else
  {
    printf("oh, some chars are duplicated in the string.\n");
  }
  
  return 0;
}
Exemplo n.º 15
0
bool
AbstractTaskFactory::TestFAITriangle()
{
  bool valid = is_unique();

  if (m_task.task_size()==4) {
    const fixed d1 = m_task.getTaskPoint(1)->get_vector_planned().Distance;
    const fixed d2 = m_task.getTaskPoint(2)->get_vector_planned().Distance;
    const fixed d3 = m_task.getTaskPoint(3)->get_vector_planned().Distance;

    valid = TestFAITriangle(d1, d2, d3);
  }
  else
    valid = false;

  return valid;
}
Exemplo n.º 16
0
AbstractQoreNode *QoreDotEvalOperatorNode::makeCallReference() {
   if (m->getArgs()) {
      parse_error("argument given to call reference");
      return this;
   }

   assert(is_unique());

   // rewrite as a call reference
   AbstractQoreNode *exp = left;
   left = 0;
   char *meth = m->takeName();
   this->deref();

   //printd(5, "made parse object method reference: exp=%p meth=%s\n", exp, meth);

   return new ParseObjectMethodReferenceNode(exp, meth);
}
Exemplo n.º 17
0
bool is_torn(int n)
{
	if(!is_unique(n))return false;
	int sum = n%100 + n/100;
	return (sum*sum == n);
}
Exemplo n.º 18
0
 void make_unique() { if (!is_unique()) data.resize_and_uniquify(length); }
Exemplo n.º 19
0
 TEST(Algorithm, EmptySequenceIsUnique)
 {
     std::vector<int> vec;
     EXPECT_TRUE(is_unique(begin(vec), end(vec)));
 }