Esempio n. 1
0
 TreeNode *addValue(vector<int> &num,int low,int high){
     if(low>high) return NULL;
     int mid = (low+high)/2;
     TreeNode *t = new TreeNode(num[mid]);
     t->left = addValue(num,low,mid-1);
     t->right = addValue(num,mid+1,high);
     return t;
 }
WebCLConfiguration::WebCLConfiguration()
    : typePrefix_("_Wcl")
    , variablePrefix_("_wcl")
    , macroPrefix_("_WCL")

    , minSuffix_("min")
    , maxSuffix_("max")
    , indentation_("    ")
    , sizeParameterType_("ulong")

    , privateAddressSpace_("private")
    , localAddressSpace_("local")
    , constantAddressSpace_("constant")
    , globalAddressSpace_("global")

    , privateRecordType_(typePrefix_ + "Privates")
    , localRecordType_(typePrefix_ + "Locals")
    , constantRecordType_(typePrefix_ + "Constants")
    , globalRecordType_(typePrefix_ + "Globals")
    , addressSpaceRecordType_(typePrefix_ + "ProgramAllocations")

    , localLimitsType_(typePrefix_ + "LocalLimits")
    , constantLimitsType_(typePrefix_ + "ConstantLimits")
    , globalLimitsType_(typePrefix_ + "GlobalLimits")

    , localMinField_(variablePrefix_ + "_locals_min")
    , localMaxField_(variablePrefix_ + "_locals_max")
    , constantMinField_(variablePrefix_ + "_constant_allocations_min")
    , constantMaxField_(variablePrefix_ + "_constant_allocations_max")

    , privatesField_("pa")
    , localLimitsField_("ll")
    , constantLimitsField_("cl")
    , globalLimitsField_("gl")

    , localRecordName_(variablePrefix_ + "_locals")
    , constantRecordName_(variablePrefix_ + "_constant_allocations")
    , programRecordName_(variablePrefix_ + "_allocations_allocation")
    , addressSpaceRecordName_(variablePrefix_ + "_allocs")

    , nullType_("uint")
    , privateNullField_("pn")
    , localNullField_("ln")
    , constantNullField_("cn")
    , globalNullField_("gn")

    , localRangeZeroingMacro_(macroPrefix_ + "_LOCAL_RANGE_INIT")

    , dataWidths_(addValue(generateWidths(2, 16), 3))
    // this may be a little bit ridiculous but at least we get a constant list initialized
    , roundingModes_(addValue(addValue(addValue(addValue(StringList(), "rte"), "rtz"), "rtp"), "rtn"))

    , localVariableRenamer_(variablePrefix_ + "_", "_")
    , privateVariableRenamer_(variablePrefix_ + "_", "_")
    , typedefRenamer_("", "")
    , anonymousStructureRenamer_(typePrefix_, "")
{
}
Esempio n. 3
0
TreeNode *addValue (TreeNode **node, int value)
{
	if (! *node)
		return new TreeNode(value);
	if (value < (*node)->value)
		(*node)->left = addValue(&(*node)->left, value);
	else
		(*node)->right = addValue(&(*node)->right, value);
	return balanseNode((*node));
}
Esempio n. 4
0
/**
 * Constructs a new ValueManager. Usually this is NOT done manually.
 * Users should use the ValueManager provided by the Core with method
 * Core::getInstance()->getValueManager().
 *
 * The constructor automatically adds prototypes for all common value types.
 * Additional prototypes can be added manually with method addPrototype().
 */
ValueManager::ValueManager() : mMutex(QMutex::Recursive),
    mRepositoryChangedCounter(0)
{
    mRepositoryChangedEvent = Core::getInstance()->getEventManager()
                              ->createEvent(NerdConstants::EVENT_VALUE_REPOSITORY_CHANGED);

// 	mRepositoryChangedEvent = eventManager
// 		->createEvent(NerdConstants::EVENT_VALUE_REPOSITORY_CHANGED);

    mRepositoryChangedCounter = new IntValue(0);
    addValue(NerdConstants::VALUE_NERD_REPOSITORY_CHANGED_COUNTER,
             mRepositoryChangedCounter);

    //add default value prototypes
    addPrototype(new IntValue());
    addPrototype(new DoubleValue());
    addPrototype(new BoolValue());
    addPrototype(new StringValue());
    addPrototype(new ColorValue());
    addPrototype(new InterfaceValue("", ""));
    addPrototype(new NormalizedDoubleValue());
    addPrototype(new QuaternionValue());
    addPrototype(new Vector3DValue());
    addPrototype(new Matrix3x3Value());
    addPrototype(new ULongLongValue());

}
Esempio n. 5
0
void APE_Tag::setYear(long i)
{
	if(i <= 0)
		removeItem(wxT("YEAR"));
	else
		addValue(wxT("YEAR"), wxString::Format(wxT("%i"), (int)i), true);
}
Esempio n. 6
0
void Statistics::countNode(const Node * node) {
	if(node == nullptr) {
		return;
	}

	addValue(nodeCounter, 1);
}
Esempio n. 7
0
bool containsNearbyDuplicate(int* nums, int numsSize, int k) {

if(numsSize < 2)
{
    return false;
}
struct Set set;

initSet(&set, numsSize);
for(int i = 0; i < numsSize; ++i)
{

    if(i>k)
    {
        removeVal(&set,nums[i-k-1]);
    }
    if(!addValue(&set, nums[i]))
    {
        releaseSet(&set);
        return true;
    }

}
releaseSet(&set);

return false;
}
int main()
{
	Tree *head = new Tree;
	head->value = -32999;
	head->left = NULL;
	head->right = NULL;
	head->prev = NULL;

	char c = 0;

	while (c != '0')
	{
		printf("\n	0 Exit\n	1 Add value to tree\n	2 Delete value from tree\n	3 Exist?\n	4 Print\n	");
		scanf("%c", &c);
		if (c == '\n')
			scanf("%c", &c);
		if (c == '1')
			addValue(head);
		if (c == '2')
			delValue(head);
		if (c == '3')
			existence(head);
		if (c == '4')
			printEl(head->left);
	}
	
	
	delTree(head->left);
	delete head;	
	return 0;
}
Esempio n. 9
0
void CharacterLoader::Load(TiXmlDocument& doc)
{
	TiXmlElement* root = doc.FirstChildElement("Body");
	root = root->FirstChildElement("Character");
	while (root)
	{
		TiXmlAttribute* attribute = root->FirstAttribute();
		std::string str = attribute->Name();
		if (str == "name")
		{
			std::string characterName = attribute->Value();
			std::string fileName;
			int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
			TiXmlElement* element = root->FirstChildElement("a");
			
			while (element)
			{
				TiXmlAttribute* attrib = element->FirstAttribute();
				while (attrib)
				{
					std::string name = attrib->Name();
					std::string value = attrib->Value();
					addValue(characterName, name, value);

					attrib = attrib->Next();
				}
				element = element->NextSiblingElement("a");
			}

		}

		root = root->NextSiblingElement("Character");
	}
}
Esempio n. 10
0
void MFVec3f::setValue(int size, float vectors[][3])
{
	clear();

	for (int n=0; n<size; n++)
		addValue(vectors[n]);
}
Esempio n. 11
0
  void operator()() {
    typedef std::vector<R> cur_vetor_t;
    typedef std::set<R> cur_set_t;
    cur_vetor_t *t = (cur_vetor_t *) data->vector;


    cur_set_t s;
for (auto e : *t)
      s.insert(e);

    auto dict = std::make_shared<storage::OrderPreservingDictionary<R>>();
for (auto e : s)
      dict->addValue(e);

    // Swap dictionary
    table->setDictionaryAt(dict, col, 0);

    for (size_t row = 0; row < t->size(); ++row) {
      table->setValue(col, row, t->at(row));
    }


    // Memory cleanup
    delete t;

  }
Esempio n. 12
0
int main()
{
	Node* cur = NULL;
	int buf = 0;
	FILE* f = fopen("test.txt", "r");
	while (!feof(f))
	{
		char symbol = fgetc(f);
		if (symbol != '(' && symbol != ' ')
		{
			if (isSign(symbol))
				cur = addChar(cur, symbol);
			if (symbol == ')')
				cur = cur->parent;
			if (isDigit(symbol))
			{
				ungetc(symbol, f);
				fscanf(f, "%d", &buf);
				cur = addValue(cur, buf);
			}
		}
	}
	while(cur->parent != NULL)
		cur = cur->parent;
	List *top = new List();
	Stack *stack = new Stack();
	stack->top = top;
	postorderPrint(cur, stack);
	printf("\n");
	printf("result = %d\n", stack->top->next->value);
	clearStack(stack);
}
Esempio n. 13
0
matrix_t readFromFile(FILE * data_file)
{
    unsigned int major_table_size = 0;
    unsigned int row_number=0;
    unsigned int column_number=0;
    cell_type value;
    matrix_t matrix;
    char buffer[BUFFER_SIZE];
    
    /* Read major table size */
    fgets(buffer, BUFFER_SIZE, data_file);
    sscanf(buffer, "%u", &major_table_size);
    matrix.major_table = malloc(sizeof(major_table_cell_t) * major_table_size);
    matrix.major_table_size = 0;
    
    while(fgets(buffer, BUFFER_SIZE, data_file))
    {
        sscanf(buffer, "%u %u %d", &row_number,
                                   &column_number,
                                   &value);
        addValue(&matrix, row_number, column_number, value);
    }

    return matrix;
}
Esempio n. 14
0
bool addFloat(Cjson CjsonObj, char *key, float value) {
    float *newValue = malloc(sizeof(float));
    *newValue = value;

    addValue(CjsonObj, key, newValue, CJSON_FLOAT);
    return true;
}
Esempio n. 15
0
  boost::optional<double> ScheduleDay_Impl::removeValue(const openstudio::Time& time){
    
    boost::optional<unsigned> timeIndex;

    std::vector<openstudio::Time> times = this->times();
    for (unsigned i = 0; i < times.size(); ++i){
      if (times[i] == time){
        timeIndex = i;
        break;
      }
    }

    if (!timeIndex){
      return boost::none; 
    }

    boost::optional<double> result;

    std::vector<double> values = this->values();
    OS_ASSERT(values.size() == times.size());

    clearValues();
    for (unsigned i = 0; i < times.size(); ++i){
      if (i == *timeIndex){
        result = values[i];
      }else{
        addValue(times[i], values[i]);
      }
    }

    return result;
  }
Esempio n. 16
0
bool addInt(Cjson CjsonObj, char *key, int value) {
    int *newValue = malloc(sizeof(int));
    *newValue = value;

    addValue(CjsonObj, key, newValue, CJSON_INT);
    return true;
}
Esempio n. 17
0
ScheduleDay::ScheduleDay(const Model& model, double value)
  : ScheduleBase(ScheduleDay::iddObjectType(), model)
{
  OS_ASSERT(getImpl<detail::ScheduleDay_Impl>());

  addValue(Time(1, 0), value);
}
int handleData(coap_rw_buffer_t* scratch,
               const coap_packet_t* inpkt,
               coap_packet_t* outpkt,
               uint8_t id_hi, uint8_t id_lo)
{
    int temperature = getTemperature(scratch, inpkt, outpkt, id_hi, id_lo);

    printf("Received temperature %d\n", temperature);

    addValue(temperature);

    int average_temp = getSum() / getCount();

    printf("Average temperature %d\n", average_temp);

    if (average_temp < YELLOW_TEMP * 100) {
        setLed(LEDGREEN_PIN);
    } else {
        if (average_temp < RED_TEMP * 100) {
            setLed(LEDYELLOW_PIN);
        } else {
            setLed(LEDRED_PIN);
        }
    }

    return 0;
}
Esempio n. 19
0
 bool ScheduleDay_Impl::addValue(const openstudio::Time& untilTime, const Quantity& value) {
   OptionalDouble dval = toDouble(value);
   if (dval) {
     return addValue(untilTime,*dval);
   }
   return false;
 }
Esempio n. 20
0
void ofxTween::setParameters(int _id,  ofxEasing & _easing, ofxEasingType _type,  float _from, float _to, unsigned _duration, unsigned _delay){
	from.clear();
	to.clear();
	change.clear();
	pTarget.clear();

	id 		= _id;
	type 	= _type;
	easing 	= &_easing;
	if(easingFunction) delete easingFunction;
	switch(type){
	case easeIn:
		easingFunction = new ofxTweenDelegate(easing, &ofxEasing::easeIn);
	break;
	case easeOut:
		easingFunction = new ofxTweenDelegate(easing, &ofxEasing::easeOut);
	break;
	case easeInOut:
		easingFunction = new ofxTweenDelegate(easing, &ofxEasing::easeInOut);
	break;
	}

	addValue(_from,_to);
	if(frameBased){
		duration = _duration;
		delay = _delay;
	}else{
		duration = _duration*1000;
		delay = _delay*1000;
	}
	start();

	completed = false;
	running = true;
}
Esempio n. 21
0
void MFInt32::setValue(int size, int values[])
{
	clear();

	for (int n=0; n<size; n++)
		addValue(values[n]);
}
Esempio n. 22
0
void read_config(char *cfilename, int type) {
   FILE *fp;
   int length;
   unsigned int len = 0;
   char *line = NULL;
   char *value = NULL;
   int key;

   fp = fopen(cfilename, "r");
   if(fp != NULL) {
      while((length = getline(&line, &len, fp)) != -1) {
         if (length > 3 && *line != '#') {
            line[length-1] = 0;
            value = strchr(line, ' ');
            if (value != NULL) {
               // split line into key, value
               *value = 0;
               value++;
            }
            key = getKey(line);
            if (key < KEY_COUNT) {
               if (key != c_annotation) {
                  value = trim(value);
               }
               addValue(key, value, type);
            }
         }
      }
      if(line) free(line);
   }   
}
EOSMessage::EOSMessage(const char* messageClass)
    {
    if (messageClass != NULL)
        addValue("class", messageClass);
    this->senderName = "";
    this->receiverName = "";
    this->tmpCmdBuffer = "";
    }
Esempio n. 24
0
// fill the average with a value
// the param number determines how often value is added (weight)
// number should preferably be between 1 and size
void RunningAverage::fillValue(float value, int number)
{
	clear();
	for (int i = 0; i < number; i++) 
	{
		addValue(value);
	}
}
Esempio n. 25
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void RigHistogramCalculator::addData(const std::vector<float>& data)
{
    assert(m_histogram);
    for (size_t i = 0; i < data.size(); ++i) 
    {
        addValue(data[i]);
    }
}
void QgsDateTimeStatisticalSummary::calculate( const QVariantList& values )
{
  reset();

  Q_FOREACH ( const QVariant& variant, values )
  {
    addValue( variant );
  }
Esempio n. 27
0
void FlatListModel::set(int index, const QScriptValue &value, QList<int> *roles)
{
    Q_ASSERT(index >= 0 && index < m_values.count());

    QHash<int, QVariant> row = m_values[index];
    if (addValue(value, &row, roles))
        m_values[index] = row;
}
Esempio n. 28
0
void APE_Tag::setBeatsPerMinute(long i)
{
	// I have not found anything standard-releated for this, so I use the same name as in ID3v2
	if(i <= 0)
		removeItem(wxT("BPM"));
	else
		addValue(wxT("BPM"), wxString::Format(wxT("%i"), (int)i), true);
}
Esempio n. 29
0
void PlotWidget::addValue(double value)
{
    mKey = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0 ;
    static int counter = 0;
    counter++;

    addValue(counter/10.0, value);
}
void QgsStatisticalSummary::calculate( const QList<double> &values )
{
  reset();

  Q_FOREACH ( double value, values )
  {
    addValue( value );
  }