inline void rebuildTreeCB( Fl_Widget*, void* )
{ makeTree(); }
Example #2
0
bool PointArray::loadFile(QString fileName, size_t maxPointCount)
{
    QTime loadTimer;
    loadTimer.start();
    setFileName(fileName);
    // Read file into point data fields.  Use very basic file type detection
    // based on extension.
    uint64_t totPoints = 0;
    Imath::Box3d bbox;
    V3d offset(0);
    V3d centroid(0);
    emit loadStepStarted("Reading file");
    if (fileName.endsWith(".las") || fileName.endsWith(".laz"))
    {
        if (!loadLas(fileName, maxPointCount, m_fields, offset,
                     m_npoints, totPoints, bbox, centroid))
        {
            return false;
        }
    }
    else if (fileName.endsWith(".ply"))
    {
        if (!loadPly(fileName, maxPointCount, m_fields, offset,
                     m_npoints, totPoints, bbox, centroid))
        {
            return false;
        }
    }
#if 0
    else if (fileName.endsWith(".dat"))
    {
        // Load crappy db format for debugging
        std::ifstream file(fileName.toUtf8(), std::ios::binary);
        file.seekg(0, std::ios::end);
        totPoints = file.tellg()/(4*sizeof(float));
        file.seekg(0);
        m_fields.push_back(GeomField(TypeSpec::vec3float32(), "position", totPoints));
        m_fields.push_back(GeomField(TypeSpec::float32(), "intensity", totPoints));
        float* position = m_fields[0].as<float>();
        float* intensity = m_fields[1].as<float>();
        for (size_t i = 0; i < totPoints; ++i)
        {
            file.read((char*)position, 3*sizeof(float));
            file.read((char*)intensity, 1*sizeof(float));
            bbox.extendBy(V3d(position[0], position[1], position[2]));
            position += 3;
            intensity += 1;
        }
        m_npoints = totPoints;
    }
#endif
    else
    {
        // Last resort: try loading as text
        if (!loadText(fileName, maxPointCount, m_fields, offset,
                      m_npoints, totPoints, bbox, centroid))
        {
            return false;
        }
    }
    // Search for position field
    m_positionFieldIdx = -1;
    for (size_t i = 0; i < m_fields.size(); ++i)
    {
        if (m_fields[i].name == "position" && m_fields[i].spec.count == 3)
        {
            m_positionFieldIdx = (int)i;
            break;
        }
    }
    if (m_positionFieldIdx == -1)
    {
        g_logger.error("No position field found in file %s", fileName);
        return false;
    }
    m_P = (V3f*)m_fields[m_positionFieldIdx].as<float>();
    setBoundingBox(bbox);
    setOffset(offset);
    setCentroid(centroid);
    emit loadProgress(100);
    g_logger.info("Loaded %d of %d points from file %s in %.2f seconds",
                  m_npoints, totPoints, fileName, loadTimer.elapsed()/1000.0);
    if (totPoints == 0)
    {
        m_rootNode.reset(new OctreeNode(V3f(0), 1));
        return true;
    }

    // Sort points into octree order
    emit loadStepStarted("Sorting points");
    std::unique_ptr<size_t[]> inds(new size_t[m_npoints]);
    for (size_t i = 0; i < m_npoints; ++i)
        inds[i] = i;
    // Expand the bound so that it's cubic.  Not exactly sure it's required
    // here, but cubic nodes sometimes work better the points are better
    // distributed for LoD, splitting is unbiased, etc.
    Imath::Box3f rootBound(bbox.min - offset, bbox.max - offset);
    V3f diag = rootBound.size();
    float rootRadius = std::max(std::max(diag.x, diag.y), diag.z) / 2;
    ProgressFunc progressFunc(*this);
    m_rootNode.reset(makeTree(0, &inds[0], 0, m_npoints, &m_P[0],
                              rootBound.center(), rootRadius, progressFunc));
    // Reorder point fields into octree order
    emit loadStepStarted("Reordering fields");
    for (size_t i = 0; i < m_fields.size(); ++i)
    {
        g_logger.debug("Reordering field %d: %s", i, m_fields[i]);
        reorder(m_fields[i], inds.get(), m_npoints);
        emit loadProgress(int(100*(i+1)/m_fields.size()));
    }
    m_P = (V3f*)m_fields[m_positionFieldIdx].as<float>();

    return true;
}
Example #3
0
/**
 * Get the core TriData
 * return a well construct TriData
 */
RDFStore* RDFStoreFactory::get(){
	return new RDFStore(makeBitSequence(*Bp), makeBitSequence(*Bo), makeBitSequence(*Bc), makeTree(*WTp), makeTree(*WToi), makeTree(*WToc));
}
Example #4
0
void showMeDepth( int n ) {
	Stack * s = makeStack( &printTreeVerticalMask );
	Tree * t;
	Tree * tmpNode;
	int i;
	char dir;
	void ** args;
	
	/* Populate random tree of size n */
	srand( time( 0 ) );
	srand( rand( ) );
	tmpNode = t = makeTree( );

	for( i=1; i<n; i++ ) {
		while( ( CHILD( tmpNode,
										/*Choose a random direction at every branch*/
										( dir = rand() % 2 ) ) ) )
			tmpNode = CHILD( tmpNode, dir );

		if( dir )
			tmpNode->right = makeTree( );
		else
			tmpNode->left  = makeTree( );
		
		tmpNode = t;
	}

	/* End tree generator */

	
	tmpNode = t;
	while( 1 ) {
		/* We've reached a leaf */
		if( !tmpNode ) {
			/* Popped last element(head) off the stack */
			if( !stackSize( s ) ) break;


			/* Print it for us(move this or add more for better resolution */
			stackPrint( s );
			printf( "\n" );
			/* Get back to parent */
			args = stackPop( s );

			switch ((uintptr_t)args[0]) {
			case 0: /* Been down left side. Visiting right */
				stackPush( s, 3, 1, i, args[2] );
				tmpNode = ((Tree *)args[2])->right;
				break;
			case 1: /* Done with left and right. finish up */
				/* i is whatever depth was for right side. left depth
					 is stored in args[1] */
				i = 1+ max( (uintptr_t)args[1], i );
				tmpNode = NULL;
				break;
			}
			
			free( args );
			continue;
		}

		/* If we're still going down a side of the tree, push this
			 node on the stack and continue onward. Worry about depth later */
		stackPush( s, 3, 0, 0, tmpNode );
		tmpNode = tmpNode->left;
		/* i is our temp counter for depth. Since we haven't reached
			 the bottom, don't start counting just yet. */
		i = 0;
	}

	freeTree( t );

	printf( "depth: %d\n", i );
}
Example #5
0
 TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
     if (preorder.size() == 0) return NULL;
     return makeTree(preorder.begin(), preorder.end(), inorder.begin(), inorder.end());
 }
Example #6
0
int
yyparse (void)
{
    int yystate;
    /* Number of tokens to shift before error messages enabled.  */
    int yyerrstatus;

    /* The stacks and their tools:
       'yyss': related to states.
       'yyvs': related to semantic values.

       Refer to the stacks through separate pointers, to allow yyoverflow
       to reallocate them elsewhere.  */

    /* The state stack.  */
    yytype_int16 yyssa[YYINITDEPTH];
    yytype_int16 *yyss;
    yytype_int16 *yyssp;

    /* The semantic value stack.  */
    YYSTYPE yyvsa[YYINITDEPTH];
    YYSTYPE *yyvs;
    YYSTYPE *yyvsp;

    YYSIZE_T yystacksize;

  int yyn;
  int yyresult;
  /* Lookahead token as an internal (translated) token number.  */
  int yytoken = 0;
  /* The variables used to return semantic value and location from the
     action routines.  */
  YYSTYPE yyval;

#if YYERROR_VERBOSE
  /* Buffer for error messages, and its allocated size.  */
  char yymsgbuf[128];
  char *yymsg = yymsgbuf;
  YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
#endif

#define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))

  /* The number of symbols on the RHS of the reduced rule.
     Keep to zero when no symbol should be popped.  */
  int yylen = 0;

  yyssp = yyss = yyssa;
  yyvsp = yyvs = yyvsa;
  yystacksize = YYINITDEPTH;

  YYDPRINTF ((stderr, "Starting parse\n"));

  yystate = 0;
  yyerrstatus = 0;
  yynerrs = 0;
  yychar = YYEMPTY; /* Cause a token to be read.  */
  goto yysetstate;

/*------------------------------------------------------------.
| yynewstate -- Push a new state, which is found in yystate.  |
`------------------------------------------------------------*/
 yynewstate:
  /* In all cases, when you get here, the value and location stacks
     have just been pushed.  So pushing a state here evens the stacks.  */
  yyssp++;

 yysetstate:
  *yyssp = yystate;

  if (yyss + yystacksize - 1 <= yyssp)
    {
      /* Get the current used size of the three stacks, in elements.  */
      YYSIZE_T yysize = yyssp - yyss + 1;

#ifdef yyoverflow
      {
        /* Give user a chance to reallocate the stack.  Use copies of
           these so that the &'s don't force the real ones into
           memory.  */
        YYSTYPE *yyvs1 = yyvs;
        yytype_int16 *yyss1 = yyss;

        /* Each stack pointer address is followed by the size of the
           data in use in that stack, in bytes.  This used to be a
           conditional around just the two extra args, but that might
           be undefined if yyoverflow is a macro.  */
        yyoverflow (YY_("memory exhausted"),
                    &yyss1, yysize * sizeof (*yyssp),
                    &yyvs1, yysize * sizeof (*yyvsp),
                    &yystacksize);

        yyss = yyss1;
        yyvs = yyvs1;
      }
#else /* no yyoverflow */
# ifndef YYSTACK_RELOCATE
      goto yyexhaustedlab;
# else
      /* Extend the stack our own way.  */
      if (YYMAXDEPTH <= yystacksize)
        goto yyexhaustedlab;
      yystacksize *= 2;
      if (YYMAXDEPTH < yystacksize)
        yystacksize = YYMAXDEPTH;

      {
        yytype_int16 *yyss1 = yyss;
        union yyalloc *yyptr =
          (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
        if (! yyptr)
          goto yyexhaustedlab;
        YYSTACK_RELOCATE (yyss_alloc, yyss);
        YYSTACK_RELOCATE (yyvs_alloc, yyvs);
#  undef YYSTACK_RELOCATE
        if (yyss1 != yyssa)
          YYSTACK_FREE (yyss1);
      }
# endif
#endif /* no yyoverflow */

      yyssp = yyss + yysize - 1;
      yyvsp = yyvs + yysize - 1;

      YYDPRINTF ((stderr, "Stack size increased to %lu\n",
                  (unsigned long int) yystacksize));

      if (yyss + yystacksize - 1 <= yyssp)
        YYABORT;
    }

  YYDPRINTF ((stderr, "Entering state %d\n", yystate));

  if (yystate == YYFINAL)
    YYACCEPT;

  goto yybackup;

/*-----------.
| yybackup.  |
`-----------*/
yybackup:

  /* Do appropriate processing given the current state.  Read a
     lookahead token if we need one and don't already have one.  */

  /* First try to decide what to do without reference to lookahead token.  */
  yyn = yypact[yystate];
  if (yypact_value_is_default (yyn))
    goto yydefault;

  /* Not known => get a lookahead token if don't already have one.  */

  /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol.  */
  if (yychar == YYEMPTY)
    {
      YYDPRINTF ((stderr, "Reading a token: "));
      yychar = yylex ();
    }

  if (yychar <= YYEOF)
    {
      yychar = yytoken = YYEOF;
      YYDPRINTF ((stderr, "Now at end of input.\n"));
    }
  else
    {
      yytoken = YYTRANSLATE (yychar);
      YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
    }

  /* If the proper action on seeing token YYTOKEN is to reduce or to
     detect an error, take that action.  */
  yyn += yytoken;
  if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
    goto yydefault;
  yyn = yytable[yyn];
  if (yyn <= 0)
    {
      if (yytable_value_is_error (yyn))
        goto yyerrlab;
      yyn = -yyn;
      goto yyreduce;
    }

  /* Count tokens shifted since error; after three, turn off error
     status.  */
  if (yyerrstatus)
    yyerrstatus--;

  /* Shift the lookahead token.  */
  YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);

  /* Discard the shifted token.  */
  yychar = YYEMPTY;

  yystate = yyn;
  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  *++yyvsp = yylval;
  YY_IGNORE_MAYBE_UNINITIALIZED_END

  goto yynewstate;


/*-----------------------------------------------------------.
| yydefault -- do the default action for the current state.  |
`-----------------------------------------------------------*/
yydefault:
  yyn = yydefact[yystate];
  if (yyn == 0)
    goto yyerrlab;
  goto yyreduce;


/*-----------------------------.
| yyreduce -- Do a reduction.  |
`-----------------------------*/
yyreduce:
  /* yyn is the number of a rule to reduce with.  */
  yylen = yyr2[yyn];

  /* If YYLEN is nonzero, implement the default value of the action:
     '$$ = $1'.

     Otherwise, the following line sets YYVAL to garbage.
     This behavior is undocumented and Bison
     users should not rely upon it.  Assigning to YYVAL
     unconditionally makes the parser a bit smaller, and it avoids a
     GCC warning that YYVAL may be used uninitialized.  */
  yyval = yyvsp[1-yylen];


  YY_REDUCE_PRINT (yyn);
  switch (yyn)
    {
        case 2:
#line 49 "tp.y" /* yacc.c:1646  */
    {printf("Prog !!!!!!!!!!! \n");evalMain((yyvsp[-1].T),(yyvsp[-3].T));}
#line 1255 "tp_y.c" /* yacc.c:1646  */
    break;

  case 3:
#line 52 "tp.y" /* yacc.c:1646  */
    { (yyval.T) =  makeTree(DECL_LIST, 1, (yyvsp[0].T));}
#line 1261 "tp_y.c" /* yacc.c:1646  */
    break;

  case 4:
#line 53 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(DECL_LIST, 2, (yyvsp[-1].T),(yyvsp[0].T));}
#line 1267 "tp_y.c" /* yacc.c:1646  */
    break;

  case 5:
#line 54 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(DECL_LIST, 2, (yyvsp[-1].T),(yyvsp[0].T));}
#line 1273 "tp_y.c" /* yacc.c:1646  */
    break;

  case 6:
#line 55 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(DECL_LIST, 2, (yyvsp[-1].T),(yyvsp[0].T));}
#line 1279 "tp_y.c" /* yacc.c:1646  */
    break;

  case 7:
#line 60 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeVar((yyvsp[-1].S));}
#line 1285 "tp_y.c" /* yacc.c:1646  */
    break;

  case 8:
#line 61 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(AFFECT,2,makeLeafStr(ID, (yyvsp[-3].S)),(yyvsp[-1].T));}
#line 1291 "tp_y.c" /* yacc.c:1646  */
    break;

  case 9:
#line 74 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(IF, 3, (yyvsp[-4].T), (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1297 "tp_y.c" /* yacc.c:1646  */
    break;

  case 10:
#line 76 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(IF,2,(yyvsp[-2].T),(yyvsp[0].T));}
#line 1303 "tp_y.c" /* yacc.c:1646  */
    break;

  case 11:
#line 78 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(ADD, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1309 "tp_y.c" /* yacc.c:1646  */
    break;

  case 12:
#line 80 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(SUB, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1315 "tp_y.c" /* yacc.c:1646  */
    break;

  case 13:
#line 82 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(MUL, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1321 "tp_y.c" /* yacc.c:1646  */
    break;

  case 14:
#line 84 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(AFFECT,2,(yyvsp[-2].T),(yyvsp[0].T));}
#line 1327 "tp_y.c" /* yacc.c:1646  */
    break;

  case 15:
#line 86 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeLeafInt(CST, (yyvsp[0].I)); }
#line 1333 "tp_y.c" /* yacc.c:1646  */
    break;

  case 16:
#line 88 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeLeafStr(ID, (yyvsp[0].S)); }
#line 1339 "tp_y.c" /* yacc.c:1646  */
    break;

  case 17:
#line 90 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = (yyvsp[-1].T); }
#line 1345 "tp_y.c" /* yacc.c:1646  */
    break;

  case 18:
#line 98 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(EQ2, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1351 "tp_y.c" /* yacc.c:1646  */
    break;

  case 19:
#line 100 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(NE2, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1357 "tp_y.c" /* yacc.c:1646  */
    break;

  case 20:
#line 102 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(LE2, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1363 "tp_y.c" /* yacc.c:1646  */
    break;

  case 21:
#line 104 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(GE2, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1369 "tp_y.c" /* yacc.c:1646  */
    break;

  case 22:
#line 106 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(GT2, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1375 "tp_y.c" /* yacc.c:1646  */
    break;

  case 23:
#line 108 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = makeTree(LT2, 2, (yyvsp[-2].T), (yyvsp[0].T)); }
#line 1381 "tp_y.c" /* yacc.c:1646  */
    break;

  case 24:
#line 110 "tp.y" /* yacc.c:1646  */
    { (yyval.T) = (yyvsp[-1].T); }
#line 1387 "tp_y.c" /* yacc.c:1646  */
    break;


#line 1391 "tp_y.c" /* yacc.c:1646  */
      default: break;
    }
  /* User semantic actions sometimes alter yychar, and that requires
     that yytoken be updated with the new translation.  We take the
     approach of translating immediately before every use of yytoken.
     One alternative is translating here after every semantic action,
     but that translation would be missed if the semantic action invokes
     YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
     if it invokes YYBACKUP.  In the case of YYABORT or YYACCEPT, an
     incorrect destructor might then be invoked immediately.  In the
     case of YYERROR or YYBACKUP, subsequent parser actions might lead
     to an incorrect destructor call or verbose syntax error message
     before the lookahead is translated.  */
  YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);

  YYPOPSTACK (yylen);
  yylen = 0;
  YY_STACK_PRINT (yyss, yyssp);

  *++yyvsp = yyval;

  /* Now 'shift' the result of the reduction.  Determine what state
     that goes to, based on the state we popped back to and the rule
     number reduced by.  */

  yyn = yyr1[yyn];

  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
    yystate = yytable[yystate];
  else
    yystate = yydefgoto[yyn - YYNTOKENS];

  goto yynewstate;


/*--------------------------------------.
| yyerrlab -- here on detecting error.  |
`--------------------------------------*/
yyerrlab:
  /* Make sure we have latest lookahead translation.  See comments at
     user semantic actions for why this is necessary.  */
  yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);

  /* If not already recovering from an error, report this error.  */
  if (!yyerrstatus)
    {
      ++yynerrs;
#if ! YYERROR_VERBOSE
      yyerror (YY_("syntax error"));
#else
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
                                        yyssp, yytoken)
      {
        char const *yymsgp = YY_("syntax error");
        int yysyntax_error_status;
        yysyntax_error_status = YYSYNTAX_ERROR;
        if (yysyntax_error_status == 0)
          yymsgp = yymsg;
        else if (yysyntax_error_status == 1)
          {
            if (yymsg != yymsgbuf)
              YYSTACK_FREE (yymsg);
            yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
            if (!yymsg)
              {
                yymsg = yymsgbuf;
                yymsg_alloc = sizeof yymsgbuf;
                yysyntax_error_status = 2;
              }
            else
              {
                yysyntax_error_status = YYSYNTAX_ERROR;
                yymsgp = yymsg;
              }
          }
        yyerror (yymsgp);
        if (yysyntax_error_status == 2)
          goto yyexhaustedlab;
      }
# undef YYSYNTAX_ERROR
#endif
    }



  if (yyerrstatus == 3)
    {
      /* If just tried and failed to reuse lookahead token after an
         error, discard it.  */

      if (yychar <= YYEOF)
        {
          /* Return failure if at end of input.  */
          if (yychar == YYEOF)
            YYABORT;
        }
      else
        {
          yydestruct ("Error: discarding",
                      yytoken, &yylval);
          yychar = YYEMPTY;
        }
    }

  /* Else will try to reuse lookahead token after shifting the error
     token.  */
  goto yyerrlab1;


/*---------------------------------------------------.
| yyerrorlab -- error raised explicitly by YYERROR.  |
`---------------------------------------------------*/
yyerrorlab:

  /* Pacify compilers like GCC when the user code never invokes
     YYERROR and the label yyerrorlab therefore never appears in user
     code.  */
  if (/*CONSTCOND*/ 0)
     goto yyerrorlab;

  /* Do not reclaim the symbols of the rule whose action triggered
     this YYERROR.  */
  YYPOPSTACK (yylen);
  yylen = 0;
  YY_STACK_PRINT (yyss, yyssp);
  yystate = *yyssp;
  goto yyerrlab1;


/*-------------------------------------------------------------.
| yyerrlab1 -- common code for both syntax error and YYERROR.  |
`-------------------------------------------------------------*/
yyerrlab1:
  yyerrstatus = 3;      /* Each real token shifted decrements this.  */

  for (;;)
    {
      yyn = yypact[yystate];
      if (!yypact_value_is_default (yyn))
        {
          yyn += YYTERROR;
          if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
            {
              yyn = yytable[yyn];
              if (0 < yyn)
                break;
            }
        }

      /* Pop the current state because it cannot handle the error token.  */
      if (yyssp == yyss)
        YYABORT;


      yydestruct ("Error: popping",
                  yystos[yystate], yyvsp);
      YYPOPSTACK (1);
      yystate = *yyssp;
      YY_STACK_PRINT (yyss, yyssp);
    }

  YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
  *++yyvsp = yylval;
  YY_IGNORE_MAYBE_UNINITIALIZED_END


  /* Shift the error token.  */
  YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);

  yystate = yyn;
  goto yynewstate;


/*-------------------------------------.
| yyacceptlab -- YYACCEPT comes here.  |
`-------------------------------------*/
yyacceptlab:
  yyresult = 0;
  goto yyreturn;

/*-----------------------------------.
| yyabortlab -- YYABORT comes here.  |
`-----------------------------------*/
yyabortlab:
  yyresult = 1;
  goto yyreturn;

#if !defined yyoverflow || YYERROR_VERBOSE
/*-------------------------------------------------.
| yyexhaustedlab -- memory exhaustion comes here.  |
`-------------------------------------------------*/
yyexhaustedlab:
  yyerror (YY_("memory exhausted"));
  yyresult = 2;
  /* Fall through.  */
#endif

yyreturn:
  if (yychar != YYEMPTY)
    {
      /* Make sure we have latest lookahead translation.  See comments at
         user semantic actions for why this is necessary.  */
      yytoken = YYTRANSLATE (yychar);
      yydestruct ("Cleanup: discarding lookahead",
                  yytoken, &yylval);
    }
  /* Do not reclaim the symbols of the rule whose action triggered
     this YYABORT or YYACCEPT.  */
  YYPOPSTACK (yylen);
  YY_STACK_PRINT (yyss, yyssp);
  while (yyssp != yyss)
    {
      yydestruct ("Cleanup: popping",
                  yystos[*yyssp], yyvsp);
      YYPOPSTACK (1);
    }
#ifndef yyoverflow
  if (yyss != yyssa)
    YYSTACK_FREE (yyss);
#endif
#if YYERROR_VERBOSE
  if (yymsg != yymsgbuf)
    YYSTACK_FREE (yymsg);
#endif
  return yyresult;
}
 void init()
 { 
   root = findFree();
   makeTree(root,0);
 }
Example #8
0
Node *insert(int x,Node *root)
	{
	Node *nx=makeTree(x);
	return merge(nx,root);
	}
/**********************************************************************
Example #10
0
TreeNode* Solution::buildTree(vector<int> &A) {
    return makeTree(0,A.size()-1,A);
}
int _tmain(int argc, _TCHAR* argv[])
{
	int i;
	node* root;
	int* aSet;
	int rows;
	int cols;
	double tmp;
	int* r;
	int* point;

	root = (node*) malloc(sizeof(node));
	root->dimNumber = -1;
	root->dimVal = -1;
	root->left = NULL;
	root->right = NULL;
	root->isLeaf = 0;
	root->leafVector = NULL;
	root->id = NULL;
	
	//rows - points (vectors)
	//rows = 6;

	////// cols - dimensions - SIFT size (dimensionality)
	//cols = 2;

	//aSet = (int*) malloc( rows * cols * sizeof(int) );

	// even index - X coordinate
	// odd  index - Y coordinate
	//aSet[0] = 1;
	//aSet[1] = 1;

	//aSet[2] = 3;
	//aSet[3] = 2;

	//aSet[4] = 5;
	//aSet[5] = 3;

	//aSet[6] = 2;
	//aSet[7] = 5;

	//aSet[8] = 4;
	//aSet[9] = 6;

	//aSet[10] = 7;
	//aSet[11] = 7;
	///////////////////////////////////
	//aSet[12] = 12;
	//aSet[13] = 12;

	//aSet[14] = 15;
	//aSet[15] = 15;

	//aSet[16] = 17;
	//aSet[17] = 17;

	//aSet[18] = 68;
	//aSet[19] = 90;

	//aSet[20] = 11;
	//aSet[21] = 78;

	//srand(time(NULL));

	rows = 150000;
	cols = 128;

	tmp = rows * cols * sizeof(int);
	printf("%f\n", ((double)tmp)/1024/1024);
	printf("%d\n", sizeof(node));
	printf("%d\n", sizeof(int));
	printf("%d\n", sizeof(short));

	aSet = (int*) malloc( rows * cols * sizeof(int) );

	for (i = 0; i < rows * cols; i++ )
	{
		aSet[i] = i;
	}

	point = (int*) malloc(cols*sizeof(int));

	for (i = 0; i < cols; i++ )
	{
		point[i] = 120;
	}


	//memcpy(point, aSet, cols * sizeof(int));


	
	clock_t start = clock();

	makeTree(root, aSet, rows, cols); // <-- aSet is cleared inside this function
	//showTree(root, 0);
	
	clock_t end = clock();
	float seconds = (float)(end - start) / CLOCKS_PER_SEC;
	
	printf("construction time: %f\n", seconds);

	//------------------- search -------------------
 	start = clock();

	r = search(point, root, 50, cols);

	end = clock();
	seconds = (float)(end - start) / CLOCKS_PER_SEC;
	printf("search time: %f\n", seconds);
	int r_;
	int p_;
	// check the result

	for (i = 0; i < cols; i++)
	{
		r_ = r[i];
		p_ = point[i];

		if (r[i]== 0 && r[cols-1]== 127)
		{
			printf("Ok"); break;
		}
	}


	getchar();
	
	return 0;
}
void makeTree(node* root, int* aSet, int rows, int cols)
{
	int* vector = NULL;
	double* varianceVector;
	double* varianceVectorCpy;
	int* maxVarianceVector;
	double maxVariance;
	int maxVarianceIdx;
	double* median;
	int i;
	int leftSize = 0;
	int rightSize = 0;
	double vectorVal;
	int* leftSet;
	int* rightSet;
	node* leftNode;
	node* rightNode;
	int j = 0;
	int a = 0;

	leftNode = (node*) malloc(sizeof(node));
	leftNode->dimNumber = -1;
	leftNode->dimVal = -1;
	leftNode->left = NULL;
	leftNode->right = NULL;
	leftNode->isLeaf = 0;
	leftNode->leafVector = NULL;
	leftNode->id = NULL;

	rightNode = (node*) malloc(sizeof(node));
	rightNode->dimNumber = -1;
	rightNode->dimVal = -1;
	rightNode->left = NULL;
	rightNode->right = NULL;
	rightNode->isLeaf = 0;
	rightNode->leafVector = NULL;
	rightNode->id = NULL;

	//printf("nodes left: %d\n", nodes);
	//vector = getDimensionVector(1, aSet, rows, cols);

	varianceVector = (double*) malloc(cols * sizeof(double) );
	median = (double*) malloc(sizeof(double));

	if (median == NULL)
	{
		a = 1; 
	}

	for (i = 0; i < cols; i++)
	{
		vector = getDimensionVector(i, aSet, rows, cols);
		getVariance(&varianceVector[i], vector, rows);
		free(vector);
	}

	varianceVectorCpy = (double*) malloc(cols*sizeof(double));

	varianceVectorCpy = (double*) memcpy(varianceVectorCpy, varianceVector, cols*sizeof(double));

	qsort(varianceVectorCpy, cols, sizeof(double), dCmpfunc);

	//for (i = 0; i < cols; i++)
	//{
	//	printf("%f ", varianceVectorCpy[i]);
	//}

	for (i = 0; i < cols; i++)
	{
		maxVariance = varianceVectorCpy[cols-1-i];

		if (maxVariance != 0.0)
		{
			break;
		}
	}
	
	//if (maxVariance == 0.0)
	//{
	//	for (i = 0; i < cols; i++)
	//	{
	//		printf("%f ", varianceVectorCpy[i]);
	//	}

	//	printf("\n");
	//	printf("\n");
	//	printf("------------------------");



	//	for (i = 0; i < cols; i++)
	//	{
	//		printf("%f ", varianceVector[i]);
	//	}

	//	printf("\n");
	//	printf("\n");
	//	printf("\n");
	//	for (i =0; i < rows; i++)
	//	{
	//		for (j = 0; j < cols; j++)
	//		{
	//			printf("%d ", aSet[i+j]);
	//		}
	//		printf("\n");
	//	}
	//	a = 1;
	//}

	// find dimension number with max variance
	for (i = 0; i < cols; i++)
	{
		if (varianceVector[i] == maxVariance )
		{
			maxVarianceIdx = i;
		}
	}

	// get max variance axe
	maxVarianceVector = getDimensionVector(maxVarianceIdx, aSet, rows, cols);
	getMedian(median, maxVarianceVector, rows);

	
	// create two arrays
	// determine array sizes
	for (i = 0; i < rows; i++)
	{
		vectorVal = (double) maxVarianceVector[i];

		if (vectorVal <= *median)
		{ leftSize++; }
		else
		{ rightSize++; }
	}

	// set root values
	root->dimNumber = maxVarianceIdx;
	root->dimVal = *median;

	// get memory from branches
	leftSet = (int*) malloc(cols * leftSize * sizeof(int));
	rightSet = (int*) malloc(cols * rightSize * sizeof(int));

	// reset counters
	leftSize = 0;
	rightSize = 0;

	

	// split aSet into two parts according to median value 
	for (i = 0; i < rows; i++)
	{

		vectorVal = (double) maxVarianceVector[i];

		if (vectorVal <= *median)
		{ 
			memcpy(&leftSet[leftSize * cols], &aSet[i * cols], cols * sizeof(int)); 
			leftSize++;
		}
		else
		{ 
			memcpy(&rightSet[rightSize * cols], &aSet[i * cols], cols * sizeof(int));
			rightSize++; 
		}
	}

	//free(vector);
	free(varianceVector);
	free(varianceVectorCpy);
	free(maxVarianceVector);
	free(aSet); // delete input set (matrix) to store some memory. In futher calculation it is not used. Used only its split version
	free(median);
	
	// making a leaf or node for right and left root branches
	if (leftSize > 1)
	{
		root->left = leftNode;
		makeTree(leftNode, leftSet, leftSize, cols);
	}
	else
	{
		leftNode->isLeaf = 1;
		leftNode->leafVector = leftSet;
		root->left = leftNode;
		nodes--;
	}

	if (rightSize > 1)
	{
		root->right = rightNode;
		makeTree(rightNode, rightSet, rightSize, cols );
	}
	else
	{
		rightNode->isLeaf = 1;
		rightNode->leafVector = rightSet;
		root->right = rightNode;
		nodes--;
	}
}
Example #13
0
int main(void)
{
	int userInput = mainMenu;
	rootPointer RP = { NULL, NULL };
	member * leafNull;

	leafNull = (member *)malloc(sizeof(member)* 1);
	leafNull->color = black;
	
	leafNull = makeTree(&RP, leafNull);

	PlaySound(TEXT("bgm.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP | SND_NODEFAULT);
	while (1)
	{
		fflush(stdin);
		switch (userInput){
		case (mainMenu) :
			userInput = printMain();
			break;
		case (printMemberListInIdOrder) :
			system("cls"); //id 순으로 회원보기
			userInput = printList(RP.rootNode, leafNull);
			break;
		case (registerNewMember) : //회원등록하기
			system("cls");
			userInput = addData(&RP, leafNull);
			break;
		case (searchMember) : //회원검색하기
			system("cls");
			userInput = selectSearch(&RP, leafNull);
			break;
		case (deleteMember) : //삭제하기
			system("cls");
			userInput = selectSearch(&RP, leafNull);
			break;
		case (memberInfoModif) : //수정하기
			system("cls");
			userInput = selectSearch(&RP, leafNull);
			break;
		case (saveMemberList) : //저장하기
			system("cls");
			userInput = saveData(&RP, leafNull);
			break;
		case (quitProgram) : //종료하기 전에 저장여부 확인
			system("cls");
			userInput = askSave(&RP,leafNull);
			return 0;
		case (creditPage) : //credit
			system("cls");
			userInput = credit();
			PlaySound(TEXT("bgm.wav"), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP | SND_NODEFAULT);
			break;
		case (printMemberListInNameOrder) : //이름순으로 회원보기
			system("cls");
			userInput = printList(RP.rootNodeN, leafNull);
			break;
		}
	}

	return 0;
}
Example #14
0
int main(int argc, char *argv[])
{
    GraphType graphType;
    edgefn ef;

    opts.pfx = "";
    opts.name = "";
    opts.cnt = 1;
    graphType = init(argc, argv, &opts);
    if (opts.directed) {
	fprintf(opts.outfile, "digraph %s{\n", opts.name);
	ef = dirfn;
    }
    else {
	fprintf(opts.outfile, "graph %s{\n", opts.name);
	ef = undirfn;
    }

    switch (graphType) {
    case grid:
	makeSquareGrid(opts.graphSize1, opts.graphSize2,
		       opts.foldVal, opts.isPartial, ef);
	break;
    case circle:
	makeCircle(opts.graphSize1, ef);
	break;
    case path:
	makePath(opts.graphSize1, ef);
	break;
    case tree:
	if (opts.graphSize2 == 2)
	    makeBinaryTree(opts.graphSize1, ef);
	else
	    makeTree(opts.graphSize1, opts.graphSize2, ef);
	break;
    case trimesh:
	makeTriMesh(opts.graphSize1, ef);
	break;
    case ball:
	makeBall(opts.graphSize1, opts.graphSize2, ef);
	break;
    case torus:
	if ((opts.parm1 == 0) && (opts.parm2 == 0))
	    makeTorus(opts.graphSize1, opts.graphSize2, ef);
	else
	    makeTwistedTorus(opts.graphSize1, opts.graphSize2, opts.parm1, opts.parm2, ef);
	break;
    case cylinder:
	makeCylinder(opts.graphSize1, opts.graphSize2, ef);
	break;
    case mobius:
	makeMobius(opts.graphSize1, opts.graphSize2, ef);
	break;
    case sierpinski:
	makeSierpinski(opts.graphSize1, ef);
	break;
    case complete:
	makeComplete(opts.graphSize1, ef);
	break;
    case randomg:
	makeRandom (opts.graphSize1, opts.graphSize2, ef);
	break;
    case randomt:
	{
	    int i;
	    treegen_t* tg = makeTreeGen (opts.graphSize1);
	    for (i = 1; i <= opts.cnt; i++) {
		makeRandomTree (tg, ef);
		if (i != opts.cnt) closeOpen ();
	    }
	    freeTreeGen (tg);
	}
	makeRandom (opts.graphSize1, opts.graphSize2, ef);
	break;
    case completeb:
	makeCompleteB(opts.graphSize1, opts.graphSize2, ef);
	break;
    case hypercube:
	makeHypercube(opts.graphSize1, ef);
	break;
    case star:
	makeStar(opts.graphSize1, ef);
	break;
    case wheel:
	makeWheel(opts.graphSize1, ef);
	break;
    default:
	/* can't happen */
	break;
    }
    fprintf(opts.outfile, "}\n");

    exit(0);
}