예제 #1
0
std::vector< std::string > split(std::string const &val, char c, int flags)
{
	std::vector< std::string > res;

	std::string::const_iterator i1 = val.begin();
	std::string::const_iterator i2 = val.begin();

	while (i2 != val.end()) {
		if (*i2 == c) {
			std::string new_val(i1, i2);
			if (flags & STRIP_SPACES)
				strip(new_val);
			if (!(flags & REMOVE_EMPTY) || !new_val.empty())
				res.push_back(new_val);
			++i2;
			if (flags & STRIP_SPACES) {
				while (i2 != val.end() && *i2 == ' ')
					++i2;
			}

			i1 = i2;
		} else {
			++i2;
		}
	}

	std::string new_val(i1, i2);
	if (flags & STRIP_SPACES)
		strip(new_val);
	if (!(flags & REMOVE_EMPTY) || !new_val.empty())
		res.push_back(new_val);

	return res;
}
예제 #2
0
void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {
  __ bind(_entry);
  assert(addr()->is_register(), "Precondition.");
  assert(new_val()->is_register(), "Precondition.");
  Register new_val_reg = new_val()->as_register();
  __ cbz(new_val_reg, _continuation);
  ce->store_parameter(addr()->as_pointer_register(), 0);
  __ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::g1_post_barrier_slow_id)));
  __ b(_continuation);
}
예제 #3
0
void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {
  __ bind(_entry);
  ce->check_reserved_argument_area(16); // RT stub needs 2 spill slots.
  assert(addr()->is_register(), "Precondition.");
  assert(new_val()->is_register(), "Precondition.");
  Register new_val_reg = new_val()->as_register();
  __ z_ltgr(new_val_reg, new_val_reg);
  __ branch_optimized(Assembler::bcondZero, _continuation);
  __ z_lgr(Z_R1_scratch, addr()->as_pointer_register());
  ce->emit_call_c(Runtime1::entry_for (Runtime1::g1_post_barrier_slow_id));
  CHECK_BAILOUT();
  __ branch_optimized(Assembler::bcondAlways, _continuation);
}
예제 #4
0
  VPtr lookup_or_create(const K &key) {
    VPtr val;
    list<VPtr> to_release;
    {
      Mutex::Locker l(lock);
      bool retry = false;
      do {
	retry = false;
	typename map<K, pair<WeakVPtr, V*>, C>::iterator i = weak_refs.find(key);
	if (i != weak_refs.end()) {
	  val = i->second.first.lock();
	  if (val) {
	    lru_add(key, val, &to_release);
	    return val;
	  } else {
	    retry = true;
	  }
	}
	if (retry)
	  cond.Wait(lock);
      } while (retry);

      V *new_value = new V();
      VPtr new_val(new_value, Cleanup(this, key));
      weak_refs.insert(make_pair(key, make_pair(new_val, new_value)));
      lru_add(key, new_val, &to_release);
      return new_val;
    }
  }
예제 #5
0
cst_val *int_val(int i)
{
    cst_val *v = new_val();
    CST_VAL_TYPE(v) = CST_VAL_TYPE_INT;
    CST_VAL_INT(v) = i;
    return v;
}
예제 #6
0
cst_val *val_new_typed(int type,void *vv)
{
    cst_val *v = new_val();
    CST_VAL_TYPE(v) = type;
    CST_VAL_VOID(v) = vv;
    return v;
}
예제 #7
0
cst_val *float_val(float f)
{
    cst_val *v = new_val();
    CST_VAL_TYPE(v) = CST_VAL_TYPE_FLOAT;
    CST_VAL_FLOAT(v) = f;
    return v;
}
예제 #8
0
void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {
  __ bind(_entry);

  assert(addr()->is_register(), "Precondition.");
  assert(new_val()->is_register(), "Precondition.");
  Register addr_reg = addr()->as_pointer_register();
  Register new_val_reg = new_val()->as_register();
  __ br_on_reg_cond(Assembler::rc_z, /*annul*/false, Assembler::pt,
                    new_val_reg, _continuation);
  __ delayed()->nop();

  __ call(Runtime1::entry_for(Runtime1::Runtime1::g1_post_barrier_slow_id));
  __ delayed()->mov(addr_reg, G4);
  __ br(Assembler::always, false, Assembler::pt, _continuation);
  __ delayed()->nop();
}
예제 #9
0
cst_val *string_val(const char *s)
{
    cst_val *v = new_val();
    CST_VAL_TYPE(v) = CST_VAL_TYPE_STRING;
    /* would be nice to note if this is a deletable string or not */
    CST_VAL_STRING_LVAL(v) = cst_strdup(s);
    return v;
}
예제 #10
0
cst_val *cons_val(const cst_val *a, const cst_val *b)
{
    cst_val *v = new_val();
    CST_VAL_CAR(v)=((!a || cst_val_consp(a)) ? 
		    (cst_val *)(void *)a:val_inc_refcount(a));
    CST_VAL_CDR(v)=((!b || cst_val_consp(b)) ? 
		    (cst_val *)(void *)b:val_inc_refcount(b));
    return v;
}
예제 #11
0
void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {
    __ bind(_entry);

    assert(addr()->is_register(), "Precondition.");
    assert(new_val()->is_register(), "Precondition.");
    Register addr_reg = addr()->as_pointer_register();
    Register new_val_reg = new_val()->as_register();

    if (__ is_in_wdisp16_range(_continuation)) {
        __ br_null(new_val_reg, /*annul*/false, Assembler::pt, _continuation);
    } else {
        __ cmp(new_val_reg, G0);
        __ brx(Assembler::equal, false, Assembler::pn, _continuation);
    }
    __ delayed()->nop();

    __ call(Runtime1::entry_for(Runtime1::Runtime1::g1_post_barrier_slow_id));
    __ delayed()->mov(addr_reg, G4);
    __ br(Assembler::always, false, Assembler::pt, _continuation);
    __ delayed()->nop();
}
예제 #12
0
std::vector< std::string > split(std::string const &val, const std::string& delim)
{
	/* this might be slow but its very convenient so long as you
	   aren't calling it too often */

	std::vector< std::string > res;
	std::string::const_iterator i1 = val.begin();
	std::string::const_iterator i2 = val.begin();

	while (i2 != val.end()) {
		if(delim.find(*i2) != std::string::npos) {
			std::string new_val(i1, i2);
			res.push_back(new_val);
			while(delim.find(*(++i2)) != std::string::npos) {}
			i1 = i2;
		}
		++i2;
	}
	std::string new_val(i1,i2);
	if(!new_val.empty()) {
		res.push_back(new_val);
	}
	return res;
}
예제 #13
0
파일: arith_test.cpp 프로젝트: rmsk2/rmsk2
unsigned int rotor_machine_provider::new_object(tlv_entry& params, tlv_stream *out_stream)
{
    unsigned int result = ERR_OK;
    string new_object_name;
    tlv_entry tlv_handle;
    rotor_machine *machine;
    rotor_machine_proxy *new_object;
    
    make_handle(new_object_name);
    
    do
    {
        // Did we receive a TLV byte array?
        if (params.tag != TAG_BYTE_ARRAY)
        {
            result = out_stream->write_error_tlv(ERR_SYNTAX_INPUT);
            break;
        }
        
        string machine_state((char *)params.value.data(), params.value.length());
        
        // Attempt to restore a rotor_machine object from the state sent by the client
        machine = rmsk::restore_from_data(machine_state);
        
        // Did restoring machine state work?
        if (machine ==  NULL)
        {
            // No
            result = out_stream->write_error_tlv(ERR_OBJECT_CREATE);
            break;            
        }
        
        // Yes        
        new_object = new rotor_machine_proxy(machine);
        
        pair<void *, service_provider *> new_val(new_object, this);
    
        registry->add_object(new_object_name, new_val);
        tlv_handle.to_string(new_object_name);

        // Tell client about the new handle and write end of result stream marker.
        result = out_stream->write_success_tlv(tlv_handle);        
    
    } while(0);
    
    return result;
}
예제 #14
0
파일: arith_test.cpp 프로젝트: rmsk2/rmsk2
unsigned int arithmetic_provider::new_object(tlv_entry& params, tlv_stream *out_stream)
{
    unsigned int result = ERR_OK;
    string new_object_name;
    arithmetic *new_object = new arithmetic();
    tlv_entry tlv_handle;
    
    make_handle(new_object_name);
    pair<void *, service_provider *> new_val(new_object, this);
    
    registry->add_object(new_object_name, new_val);
    tlv_handle.to_string(new_object_name);
    
    // Tell client about the new handle and write end of result stream marker.
    result = out_stream->write_success_tlv(tlv_handle);

    return result;
}
예제 #15
0
파일: arith_test.cpp 프로젝트: rmsk2/rmsk2
unsigned int random_provider::new_object(tlv_entry& params, tlv_stream *out_stream)
{
    unsigned int result = ERR_OK;
    string new_object_name;
    tlv_entry tlv_handle;
    alphabet<char> *new_alpha;
    random_proxy *new_object;
    string alpha_spec;
    
    make_handle(new_object_name);
    
    do
    {
        // Did we receive a TLV string?
        if (params.tag != TAG_STRING)
        {
            result = out_stream->write_error_tlv(ERR_SYNTAX_INPUT);
            break;
        }
        
        if (!params.tlv_convert(alpha_spec))
        {
            result = out_stream->write_error_tlv(ERR_SYNTAX_INPUT);
            break;
        }
        
        new_alpha = new alphabet<char>(alpha_spec.c_str(), alpha_spec.length());
        new_object = new random_proxy(new_alpha);
                
        pair<void *, service_provider *> new_val(new_object, this);
    
        registry->add_object(new_object_name, new_val);
        tlv_handle.to_string(new_object_name);

        // Tell client about the new handle and write end of result stream marker.
        result = out_stream->write_success_tlv(tlv_handle);        
    
    } while(0);
    
    return result;
}
예제 #16
0
		void draw_text(const Rect* r, const char* str)
		{
			Gdiplus::SolidBrush* brush = new Gdiplus::SolidBrush(*color);
			if(brush == NULL) return;

			st count = cl::StringUtil::char_to_wchar_count(str);
			wchar* wstr = cl_alloc_type_with_count(wchar, count);
			if(wstr == NULL) { delete brush;  return; }
			cl::StringUtil::char_to_wchar(wstr, count, str);

			Gdiplus::Region old_val;
			graphics->GetClip(&old_val);

			Gdiplus::Region new_val(TO_RECT(r));
			graphics->SetClip(&new_val);

			graphics->DrawString(wstr, -1, font, TO_POINTF(((Point*)r)), brush);
			graphics->SetClip(&old_val);
			cl_free(wstr);
			delete brush;
		}
예제 #17
0
int main(int argc, char *argv[]) {
  uint32_t i, j, n;
  double runtime, memused;
  int32_t x, *val;

  if (argc != 2) {
    fprintf(stderr, "Usage: %s filename\n", argv[0]);
    fprintf(stderr, "  filename must contain a set of strings, one per line, less than 100 char long\n");
    fflush(stderr);
    exit(1);
  }
  words_from_file(argv[1]);

  init_stbl(&sym_table, 0);

  val = (int32_t *) malloc(n_words * sizeof(int32_t));
  if (val == NULL) {
    fprintf(stderr, "Failed to allocate array val\n");
    exit(1);
  }

  for (i=0; i<n_words; i++) {
    x = stbl_find(&sym_table, words[i]);
    if (x < 0) {
      stbl_add(&sym_table, words[i], i);
      val[i] = i;
    } else {
      val[i] = x;
    }
  }

  printf("\n--- checking ---\n");
  for (i=0; i<n_words; i++) {
    x = stbl_find(&sym_table, words[i]);
    if (x != val[i]) {
      printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[i], x, val[i]);
      fflush(stdout);
      exit(1);
    }
  }

  printf("\n*** Added %"PRIu32" words from %s ***\n", n_words, argv[1]);

  // repeated additions of the same symbols with multiple lookups
  // warning: this code does not work (may give a false alarm)
  // if the input file contains duplicates.
  n = (n_words < 200) ?  n_words : 200;
  printf("\n*** Repeated symbol addition ***\n");
  runtime = get_cpu_time();
  for (i=0; i<10000; i++) {
    for (j=0; j<n; j++) {
      stbl_add(&sym_table, words[j], new_val(i, j));
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n_words; j++) {
      x = stbl_find(&sym_table, words[j]);
    }
    for (j=0; j<n; j++) {
      x = stbl_find(&sym_table, words[j]);
      if (x != new_val(i, j)) {
	printf("*** Error: %s, val = %"PRId32", should be %"PRId32" ***\n", words[j], x, new_val(i, j));
	fflush(stdout);
	exit(1);
      }
    }
    for (j=0; j<n_words; j++) {
      x = stbl_find(&sym_table, words[j]);
    }
  }


  runtime = get_cpu_time() - runtime;
  memused = mem_size() / (1024 * 1024);
  printf("Adding 10000 times the same %"PRIu32" words + repeated lookups\n", n);
  printf("Runtime: %.4f s\n", runtime);
  printf("Table size: %"PRIu32" (nelems = %"PRIu32", ndeleted = %"PRIu32")\n",
	sym_table.size, sym_table.nelems, sym_table.ndeleted);
  if (memused > 0) {
    printf("Memory used: %.2f MB\n", memused);
  }

  clear_words();
  free(val);
  delete_stbl(&sym_table);

  return 0;
}
예제 #18
0
CliqueTree Inference::CreateCliqueTreeHMMFast( vector<Factor> factors )
{

    int maxVar = 0;
	// get the max var id
	for ( vector<Factor>::iterator iter = factors.begin();
		iter != factors.end(); iter ++ )
	{
		double max_now = iter->var.max();
		if ( max_now > maxVar )
		{
			maxVar = max_now;
		}
	}
    int numNodes = maxVar - 1;
    int card = factors[0].card(0);

    CliqueTree P(numNodes);
    //P.cliqueList = repmat(struct('var', [], 'card', [], 'val', []), numNodes, 1);
    //P.edges = zeros(numNodes);

	for ( int i = 0; i != numNodes; i++ )
	{
        P.cliqueList[i].var << i+1 << i+2;
        P.cliqueList[i].card << card << card;
        P.cliqueList[i].val = ones<vec>(card * card);
	    
        if (i > 0)
	    {
	        P.edges(i, i-1) = 1;
	        P.edges(i-1, i) = 1;
        }
	}

    // the name of the variable starts from 1 !!!!
    for ( int i = 0; i != factors.size(); i ++ )
	{
        Factor f = factors[i];
        int cliqueIdx = 0;
        if (f.var.n_rows == 1)
	    {
            if (f.var(0) > 1)
	        {
                cliqueIdx = f.var(0) - 1;
	        }else{
                cliqueIdx = 1;
	        }
	        
            vec updateIdxs;
            mat assignments = zeros<mat>(card, 2);
            vec cards;
            cards << card << card;
	        for ( int assignment = 0; assignment != card; assignment ++ )
	        {
               if (f.var(0) == cliqueIdx)
	           {
                   assignments.col(0) = linspace<vec>(0, card - 1, card);
                   assignments.col(1) = assignment*ones<vec>(card);
                   updateIdxs = Utils::AssignmentToIndex(assignments, cards);
	           }else{
                   assignments.col(1) = linspace<vec>(0, card - 1, card);
                   assignments.col(0) = assignment*ones<vec>(card);
                   updateIdxs = Utils::AssignmentToIndex(assignments, cards);
               }
               for (int step = 0; step != updateIdxs.n_rows; step ++)
               {
                   P.cliqueList[cliqueIdx - 1].val(updateIdxs(step)) += f.val(step);
               }
	        }        
	    }else{
            if ( f.var.n_rows != 2 )
            {
                std::cout << "ERROR: var more than 2!" << std::endl;
            }
            cliqueIdx = min(f.var);
            if (f.var(0) > f.var(1))
	        {
	            // % sort the factor val so it's in increasing var order
                uvec order = sort_index(f.var); //%#ok
                mat oldAssignments = Utils::IndexToAssignment(linspace<vec>(0,f.val.n_rows-1,f.val.n_rows), f.card);
                mat newAssignments = oldAssignments;
                // (:, order)
                for (int step = 0; step != oldAssignments.n_cols; step ++)
                {
                    newAssignments.col(step) = oldAssignments.col(order(step));
                }
                vec new_card = f.card;
                for (int step = 0; step != f.card.n_rows; step ++)
                {
                    new_card(step) = f.card(order(step));
                }
                f.card = new_card;
                f.var = sort(f.var);
                vec new_index = Utils::AssignmentToIndex(newAssignments, f.card);
                vec new_val = f.val;
                for ( int step = 0; step != f.val.n_rows; step ++ )
                {
                    new_val(step) = f.val( new_index(step) );
                }
                f.val = new_val;
            }

            P.cliqueList[cliqueIdx - 1].val += f.val;
	    }
	}
    return P;
}
예제 #19
0
std::vector< std::string > parenthetical_split(std::string const &val,
		const char separator, std::string const &left,
		std::string const &right,int flags)
{
	std::vector< std::string > res;
	std::vector<char> part;
	bool in_parenthesis = false;

	std::string::const_iterator i1 = val.begin();
	std::string::const_iterator i2 = val.begin();

	std::string lp=left;
	std::string rp=right;

	if(left.size()!=right.size()){
		ERR_GENERAL << "Left and Right Parenthesis lists not same length\n";
		return res;
	}

	while (i2 != val.end()) {
		if(!in_parenthesis && separator && *i2 == separator){
			std::string new_val(i1, i2);
			if (flags & STRIP_SPACES)
				strip(new_val);
			if (!(flags & REMOVE_EMPTY) || !new_val.empty())
				res.push_back(new_val);
			++i2;
			if (flags & STRIP_SPACES) {
				while (i2 != val.end() && *i2 == ' ')
					++i2;
			}
			i1=i2;
			continue;
		}
		if(!part.empty() && *i2 == part.back()){
			part.pop_back();
			if(!separator && part.empty()){
				std::string new_val(i1, i2);
				if (flags & STRIP_SPACES)
					strip(new_val);
				res.push_back(new_val);
				++i2;
				i1=i2;
			}else{
				if (part.empty())
					in_parenthesis = false;
				++i2;
			}
			continue;
		}
		bool found=false;
		for(size_t i=0; i < lp.size(); i++){
			if (*i2 == lp[i]){
				if (!separator && part.empty()){
					std::string new_val(i1, i2);
					if (flags & STRIP_SPACES)
						strip(new_val);
					res.push_back(new_val);
					++i2;
					i1=i2;
				}else{
					++i2;
				}
				part.push_back(rp[i]);
				found=true;
				break;
			}
		}
		if(!found){
			++i2;
		} else
			in_parenthesis = true;
	}

	std::string new_val(i1, i2);
	if (flags & STRIP_SPACES)
		strip(new_val);
	if (!(flags & REMOVE_EMPTY) || !new_val.empty())
		res.push_back(new_val);

	if(!part.empty()){
			ERR_GENERAL << "Mismatched parenthesis:\n"<<val<<"\n";;
	}

	return res;
}