Пример #1
0
bool
CJson::
matchObject(const ValueP &value, const std::string &match, ValueP &value1)
{
  if (isDebug())
    std::cerr << "matchObject \'" << match << "\'" << std::endl;

  if (! value->isObject()) {
    if (! isQuiet())
      std::cerr << value->typeName() << " is not an object" << std::endl;
    return false;
  }

  Object *obj = value->cast<Object>();

  if (match == "?" || match == "?keys") {
    std::vector<std::string> names;

    obj->getNames(names);

    Array *array = createArray();

    for (const auto &n : names) {
      String *str = createString(n);

      array->addValue(ValueP(str));
    }

    value1 = ValueP(array);
  }
  else if (match == "?type") {
    String *str = createString(obj->typeName());

    value1 = ValueP(str);
  }
  else if (match == "?values") {
    Values values;

    obj->getValues(values);

    Array *array = createArray();

    for (const auto &v : values)
      array->addValue(v);

   value1 = ValueP(array);
  }
  else {
    if (! obj->getNamedValue(match, value1)) {
      if (! isQuiet())
        std::cerr << "no value \'" << match << "\'" << std::endl;
      return false;
    }
  }

  return true;
}
Пример #2
0
int main(int argc, char* argv[])
{
    assert(argc == 3 && "Please input 'length of array' and 'max valur' in argv");

    srand(time(NULL));
    int len=atoi(argv[1]);
    int maxVal=atoi(argv[2]);
    int m=rand()%maxVal+1, n=rand()%maxVal+1;
    if(m>n)
        swap(&m, &n);

    node *head=(node*)malloc(len*sizeof(node));
    assert(head != NULL && "malloc error");

    /* create test case */
    head = createArray(head, len, maxVal);

    printf("Origin list:\n");
    printList(head, len);
    printf("Reverse between %d %d:\n",m,n);
    head = reverseBetween(head, m, n);
    printList(head,len);

    /* release the memory */
    freeList(head);

    return 0;
}
Пример #3
0
int main(){
	circular_array *c = createArray(7);
	for(int i = 0; i < 7; ++i){
		ca_set(c, i, i);
	}
	int isCorrect = 0;
	//Check
	for(int i = 0; i < 7; ++i){
		if(ca_get(c, i) != i){
			isCorrect = 1;
			printf("Failure in Circular array, piecewise, function access. Should be %d, is %f\n", i, ca_get(c, i));
		}
		if(c->arr[i] != i){
			isCorrect = 1;
			printf("Failure in Circular array, piecewise, raw access. Should be %d, is %f\n", i, ca_get(c, i));
		}
	}
	for(int i = 7; i < 14; ++i){
		double testVal = i - 7.0;
		if(ca_get(c, i) != testVal){
			isCorrect = 1;
			printf("Failure in Circular array, piecewise, function access, overflow. Should be %f, is %f\n", testVal, ca_get(c, i));
		}
	}
	return isCorrect;
}
Пример #4
0
//-------------------------------------------------------------------------------------------------------------------
char* bytebuffer::getBufferLeft()
{
    unsigned int size = _WritePos - _ReadPos;
    char* ret = createArray(size);
    memcpy(ret,_buffer+_ReadPos,size);
    return ret;
}
Пример #5
0
static void createAndFillArray(perfContext *aContext)
{
    FILE *sFileHandle      = NULL;

    sFileHandle = fopen(aContext->mFileName, "r");

    if (sFileHandle == NULL)
    {
        if (errno == ENOENT)
        {
            (void)fprintf(stderr, "File not found.\n");
            exit(1);
        }
        else
        {
            (void)fprintf(stderr, "Unexpected error. %s (errno %d)\n", strerror(errno), errno);
            exit(1);
        }
    }
    else
    {
    }

    aContext->mCount = getCountFromFile(sFileHandle);

    createArray(aContext);

    fillArray(sFileHandle, aContext);
}
Пример #6
0
//TransformedDomainRecursiveFilter_Horizontal
void TDRF_H(float** channel, float** derivatives, float sigma, int h, int w){
    float a = expf(-sqrtf(2)/sigma);

    //V
    float** V = createArray(h,w);
    for (int row = 0; row < h; row++) {
        for (int col = 0; col < w; col++) {
                V[row][col] = powf(a,derivatives[row][col]);
        }
    }
    //LEFT->RIGHT FILTER
    for (int row = 0; row < h; row++) {
        for (int col = 1; col < w; col++) {
                channel[row][col] = channel[row][col] + V[row][col]*(channel[row][col - 1] - channel[row][col]);
        }
    }
    //RIGHT->LEFT FILTER
    for (int row = 0; row < h; row++) {
        for (int col = w-2; col >= 0; col--) {
                channel[row][col] = channel[row][col] + V[row][col+1]*(channel[row][col + 1] - channel[row][col]);
        }
    }

    destroyArray(V);
}
Пример #7
0
Файл: tools.c Проект: benbaker/C
int main( int argc, char * argv[] ) {


  // Verify filename
  if (argc != 2) { throwError(1); return 0; } 

  char* str1[MAX];


  // allocate memory for array of strings.

  for (i=0; i<MAX; i++) {

    str1[i] = malloc(sizeof(char)*MAX);

  }

  int fileSize = readFile( argv[1], str1 );
  if (!fileSize) { return 0; }

  createArray   (*str1);
  sort       (*str1);
  printArray   (*str1);
  reverse      (*str1);
  printArray   (*str1);
  ascii      (*str1);

  
} // end main()
Пример #8
0
int main(int argc, char** argv)
{
    char* pArray = NULL;
    int i = 0;
    int j = 0;

    pArray = createArray(ROW_NUM, COL_NUM, sizeof(char));
    assert(pArray);

    for (i = 0; i < 1; ++i)
    {
        for (j = 0; j < COL_NUM; ++j)
        {
            char value;
            if (FAIL == fetchValue(pArray, ROW_NUM, COL_NUM, i, j, &value))
            {
                fprintf(stderr, "Failed on fetchValue\n");
            }
        }
    }

    destoryArray(pArray);

    return 0;
}
Пример #9
0
//-------------------------------------------------------------------------------------------------------------------
wchar_t* bytebuffer::readUSTRING()
{
    unsigned int size = readINT();
    wchar_t* ret = (wchar_t*)createArray(size * 2 + 2);
    readDATA((char*)ret,size * 2);
    ret[size] = 0;
    return ret;
}
Пример #10
0
//-------------------------------------------------------------------------------------------------------------------
char* bytebuffer::readASTRING()
{
    unsigned short size = readSHORT();
    char* ret = createArray(size+1);
    readDATA(ret,size);
    ret[size] = 0;
    return ret;
}
Пример #11
0
void createArray(ArrayValue* myself, char* xml) {
	Tag* valueTag;
	DictValue* curValue;
	
	myself->values = NULL;
	myself->size = 0;
	while(*xml != '\0') {
		valueTag = getNextTag(&xml);
		if(valueTag == NULL)  {
			break;
		}
		
		myself->size++;
		myself->values = realloc(myself->values, sizeof(DictValue*) * myself->size);
		curValue = (DictValue*) malloc(sizeof(DictValue));

		curValue->key = (char*) malloc(sizeof("arraykey"));
		strcpy(curValue->key, "arraykey");
		curValue->next = NULL;

		if(strcmp(valueTag->name, "dict") == 0) {
			curValue->type = DictionaryType;
			curValue = (DictValue*) realloc(curValue, sizeof(Dictionary));
			createDictionary((Dictionary*) curValue, valueTag->xml);
		} else if(strcmp(valueTag->name, "string") == 0) {
			curValue->type = StringType;
			curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
			((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(valueTag->xml) + 1));
			strcpy(((StringValue*)curValue)->value, valueTag->xml);
		} else if(strcmp(valueTag->name, "data") == 0) {
			size_t len;
			curValue->type = StringType;
			curValue = (DictValue*) realloc(curValue, sizeof(DataValue));
			((DataValue*)curValue)->value = decodeBase64(valueTag->xml, &len);
			((DataValue*)curValue)->len = len;
		} else if(strcmp(valueTag->name, "integer") == 0) {
			curValue->type = IntegerType;
			curValue = (DictValue*) realloc(curValue, sizeof(IntegerValue));
			sscanf(valueTag->xml, "%d", &(((IntegerValue*)curValue)->value));
		} else if(strcmp(valueTag->name, "array") == 0) {
			curValue->type = ArrayType;
			curValue = (DictValue*) realloc(curValue, sizeof(ArrayValue));
			createArray((ArrayValue*) curValue, valueTag->xml);
		} else if(strcmp(valueTag->name, "true/") == 0) {
			curValue->type = BoolType;
			curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
			((BoolValue*)curValue)->value = TRUE;
		} else if(strcmp(valueTag->name, "false/") == 0) {
			curValue->type = BoolType;
			curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
			((BoolValue*)curValue)->value = FALSE;
		}
		
		myself->values[myself->size - 1] = curValue;
		
		releaseTag(valueTag);
	}
}
Пример #12
0
void testHeapSortWithArray() {
	HeapType a;
	createArray(a);
	printArray(a);

	HeapSortWithArray(a);
	printf("after heap sort:\n");
	printArray(a);
}
Пример #13
0
void WLDFragmentTable::allocate()
{
    // XXX change all fragment classes to be zero-initializable and fill the arrays with zeros.
    for(uint32_t i = 0; i < MAX_FRAGMENT_KINDS; i++)
    {
        m_frags[i] = createArray(i);
        m_current[i] = (uint8_t *)m_frags[i];
    }
}
Пример #14
0
void testQuickSortWithArray() {
	array a;
	createArray(a);
	printArray(a);

	QuickSortWithArray(a, 0, a.length -1);
	printf("after quick sort:\n");
	printArray(a);
}
Пример #15
0
void testShellSortWithArray() {
	array a;
	createArray(a);
	printArray(a);

	ShellSort(a);
	printf("after shell sort:\n");
	printArray(a);
}
Пример #16
0
void testBinarySortWithArray() {
	array a;
	createArray(a);
	printArray(a);

	BinarySortWithArray(a);
	printf("after binary sort:\n");
	printArray(a);
}
Пример #17
0
void testInsertSortWithArray() {
	array a;
	createArray(a);
	printArray(a);

	InsertSortWithArray(a);
	printf("after insert sort:\n");
	printArray(a);
}
Пример #18
0
void testSelectSortWithArray() {
	array a;
	createArray(a);
	printArray(a);

	SelectSortWithArray(a);
	printf("after simple select sort:\n");
	printArray(a);
}
Пример #19
0
int main(int argc, char *argv[]) {
	int *array;
	int width, height;
	int value;
	char **stringPtr;
	int **matrix;
	
	/* testing for part 1 */
	printf("Testing Part 1\n");
	width = 5;
	height = 6;
	
	array = create2DArray(height, width);
	
	printf("Store value 7 at [3,4].\n");
	set2DElement(array, 3, 4, 7);
	
	value = get2DElement(array, 3, 4);
	printf("Retrieve value %d from [3,4]\n\n", value);
	
	free2DArray(array);
	
	
	/* testing for part 2 */
	printf("Testing Part 2\n");
	stringPtr = createStringArray(100);
	
	printf("Store string - fred\n");
	setStringArray(stringPtr, 44, "fred");
	printf("Store string - barney\n");
	setStringArray(stringPtr, 80, "barney");
	
	printf("Get string - %s\n", getStringArray(stringPtr, 44));
	printf("Get string - %s\n", getStringArray(stringPtr, 80));
	/* test with NULL string */
	printf("Get string - %s\n\n", getStringArray(stringPtr, 3));
	
	freeStringArray(stringPtr, 100);
	
	
	/* testing for part 3 */
	printf("Testing Part 3\n");
	matrix = createArray(100, 100);
	
	printf("Store 33 44 55\n");
	matrix[22][76] = 33;
	matrix[83][29] = 44;
	matrix[99][65] = 55;
	
	printf("Retrieve %d %d %d\n", matrix[22][76], matrix[83][29],
		   matrix[99][65]);
	
	freeArray(matrix, 100);
	
	return(1);
}
Пример #20
0
// read array at file pos
bool
CJson::
readArray(CStrParse &parse, Array *&array)
{
  if (! parse.isChar('['))
    return false;

  bool open = false;

  parse.skipChar();

  array = createArray();

  while (! parse.eof()) {
    parse.skipSpace();

    if (parse.isChar(']'))
      break;

    ValueP value;

    if (! readValue(parse, value)) {
      delete array;
      return false;
    }

    value->setParent(array);

    array->addValue(value);

    parse.skipSpace();

    open = false;

    if (! parse.isChar(','))
      break;

    parse.skipChar();

    open = true;
  }

  if (open) {
    delete array;
    return false;
  }

  if (! parse.isChar(']')) {
    delete array;
    return false;
  }

  parse.skipChar();

  return true;
}
Пример #21
0
void testBubbleSortWithArray() {
	array a;
	createArray(a);
	printArray(a);

	BubbleSortWithArray(a);
	printf("after bubble sort:\n");
	printArray(a);

}
Пример #22
0
bool ESAnalyserSetHistogram(ESAnalyser *analyser, ESAnalyserOptions *options)
{
	analyser->options.histogram.period = options->histogram.period/(float)1000;
	analyser->options.histogram.high = options->histogram.high;
	analyser->options.histogram.low = options->histogram.low;
	analyser->options.histogram.interval = options->histogram.interval;
	analyser->options.histogram.sample_rate = options->histogram.sample_rate;
	float val = ((float)options->histogram.high-(float)options->histogram.low)/options->histogram.interval;
	analyser->options.histogram.num_of_points = (int)val;
	analyser->options.histogram.array = createArray(analyser->options.histogram.num_of_points);
	analyser->options.histogram.normalised_array = createArray(analyser->options.histogram.num_of_points);
	
	analyser->options.histogram.count = 0;
	analyser->options.histogram.times_called = 0;
	analyser->options.histogram.total_times_called = 0;
	analyser->options.histogram.old_time_covered = 0;

	return true;
}
Пример #23
0
//-------------------------------------------------------------------------------------------------------------------
wchar_t* bytebuffer::readASTRINGtoUNICODE()
{
    unsigned short size = readSHORT();
    char* tempArray = new char[size];
    readDATA(tempArray,size);
    wchar_t* ret = (wchar_t*)createArray(size * 2 +2);
    ascii_to_unicode(ret,tempArray,size);
    delete [] tempArray;
    ret[size] = 0;
    return ret;
}
Пример #24
0
//-------------------------------------------------------------------------------------------------------------------
char* bytebuffer::readUSTRINGtoASCII()
{
    unsigned int size = readINT();
    wchar_t* tempArray = new wchar_t[size];
    readDATA((char*)tempArray,size * 2);
    char* ret = createArray(size + 1);
    unicode_to_ascii(ret,tempArray,size);
    delete [] tempArray;
    ret[size] = 0;
    return ret;
}
void InfoSlide3:: step2(float dt){
    count++;
    CCAnimation* explode = createArray((char*)"superSymbolMorph", 23);
    
    switch (count) {
        case 1:
            selectbox->setVisible(true);
            break;
        case 2:
            selectbox->setPosition(ccp(size.width / 2-200*dScaleX, size.height / 2- 220*dScaleY));
            break;
        case 3:
            selectbox->setVisible(false);
            symbolToMakeSuper->runAction(CCMoveTo::create(0.2f, symbolB->getPosition()));
            symbolB->runAction(CCMoveTo::create(0.2f, symbolToMakeSuper->getPosition()));
            break;
        case 4:
            for (int i= 0 ; i< allSymbols->count(); i++) {
                SyntaxSymbol* temp = (SyntaxSymbol*)allSymbols->objectAtIndex(i);
                CCAnimate* ani = CCAnimate::create(explode);
                if (temp->isOfType == 1) {
                    symbolTemp = symbolManager->symbolWithType(1);
                    symbolTemp->setPosition(temp->getPosition());
                    addChild(symbolTemp);
                    symbolTemp->runAction(ani);
                    temp->runAction(CCFadeTo::create(0.8f, 0));
                    allSymbolsTem->addObject(symbolTemp);
                }
                
                symbolToMakeSuper->runAction(CCFadeTo::create(0.8f, 0));
            }
            
            break;
        case 6:
            for (int j= 0 ; j< allSymbols->count(); j++) {
                SyntaxSymbol* temp = (SyntaxSymbol*)allSymbols->objectAtIndex(j);
                removeChild(temp, true);
            }
            
            for (int j= 0 ; j< allSymbolsTem->count(); j++) {
                SyntaxSymbol* temp = (SyntaxSymbol*)allSymbolsTem->objectAtIndex(j);
                removeChild(temp, true);
            }
            allSymbols->removeAllObjects();
            removeChild(symbolToMakeSuper, true);
            count = 0;
            this->unschedule(schedule_selector(InfoSlide3::step2));
            initWithSymbol();
        default:
            break;
    }
    
    
}
Пример #26
0
/*
 * Instantiates a Graph Object, which contains an ID, a running total,
 * and structures that support the stream generation of future values.
 */
Graph* createGraph(int** graph){
	Graph* g = malloc(sizeof(Graph));
	g->id = globalGraphId++;
	g->graph = graph;
	g->running = intToLongMatrix(graph);
	g->nextOrder = 0;
	g->order = createArray(size(g));
	for(int i = 0; i < size(g); i++){
		g->order[i] = 0;
	}
	advanceGraph(g);
	return g;
}
Пример #27
0
int main()
{
	printf("Enter size:");
	scanf("%d", &size);
	ar = createArray(size);
	printElements();
	// ar = resizeArray(ENLARGE_FACTOR);
	// printElements();
	addElement(3);
	addElement(4);
	addElement(5);
	addElement(6);
	printElements();
}
int main()
{
	const int lengthArray = 30000;
	Word **m = createArray(lengthArray);

	FILE *f = fopen("input.txt", "r");
	
	while (!feof(f))
	{
		char s[50];
		scanWord(s, f);
		if (s[0] != '\0')
		{
			unsigned int a = hashFunc(s, lengthArray);
			if (m[a] == NULL)
				m[a] = createWord(s);
			else
			{
				Word *tmp = m[a];
				while ((tmp->next != NULL) && (strcmp(tmp->s, s) != 0))
				{
					tmp = tmp->next;
				}
				if (strcmp(tmp->s, s) == 0)
					tmp->repeats++;
				else
					tmp->next = createWord(s);
			}
		}
	}
	fclose(f);
	
	for (int i = 0; i < lengthArray; i++)
	{
		if (m[i] != NULL)
		{
			Word *tmp = m[i];
			while (tmp != NULL)
			{
				printf("%s  -  %i\n", tmp->s, tmp->repeats);
				tmp = tmp->next;
			}
		}
	}

	clear(m, lengthArray);
	delete[] m;
	scanf("%*");
	return 0;
}
Пример #29
0
//char updatef( char*, int, int );
int main(  )
{
	int gameOver = 0;
	char filename[256] = "cw.txt";//files name
	char** board;//dynamic array of the board
	FILE* crossword;//file pointer to the file
	int x, y, words;//size of array & number of words in the puzzle
	Clue *clues;
	printf("CROSSWORD PUZZLE GAME\n\n");
	//Ask player for name of file.
	printf("Enter name of text file: ");
	printf("(default is cw.txt): ");
	//Read input from the user
	scanf("%s", filename);
	//printf("\n");
	//Open the file
	crossword = fopen(filename, "r");
	//if the crossword file does not exist, use the default that i included
	if(crossword == NULL)
	{
		crossword = fopen("cw.txt", "r");
		strcpy(filename, "cw.txt");
	}
	//If the user inputs a valid file, use it for the game
	if(crossword != NULL)
	{
		printf("Loading game file: %s\n", filename);
		fscanf(crossword, "%i %i %i\n", &x, &y, &words);
		printf("Game is %i rows x %i cols with %i words\n", x, y, words);
		clues = (Clue *)malloc(sizeof(Clue)*words);
		
		clues = readTF(crossword, words);
		fclose(crossword);
	}
	//If the user inputs an invalid file and default is not present, return error
	else
	{
		//if the file didn't open.
		perror(filename);
	}
	//Creates board to be passed through program that will hold characters
	board = createArray(x, y);
	//Plays game until completion
	play(board, words, clues, x, y, gameOver);
	
	//Frees board and clues from memory
	free(board);
	free(clues);
	return 0;
}
Пример #30
0
void stringTest() {
	size_t i;
	/* Initialize the array */
	varray** stringArray = createArray(v_str, 2);
	/* Set sample values */
	stringArray[1] = varrayPush("This is a test string");
	stringArray[2] = varrayPush("This is another test string!");
	/* Read back the values */
	printf("\nSize of stringArray: %zu\n\n", stringArray[0]->size);
	for (i = 1; i <= stringArray[0]->size; i++) {
		printf("Value at position %zu: %s\n", i, stringArray[i]->str);
	}
	stringArray[0]->clear(stringArray);
}