Exemple #1
0
tree *delete_tree(tree *t, int k) {
    tree * x = Descend(t, k);
    if (x == NULL)
        printf("lol1\n");

    if (x->left == NULL && x->right == NULL)
        t = ReplaceNode(t, x, NULL);

    else if (x->left == NULL)
        t = ReplaceNode(t, x, x->right);

    else if (x->right == NULL)
        t = ReplaceNode(t, x, x->left);

    else {
        tree * y = succ(x);
        t = ReplaceNode(t, y, y->right);
        x->left->parent = y;
        y->left = x->left;

        if (x->right != NULL)
            x->right->parent = y;

        y->right = x->right;
        t = ReplaceNode(t, x, y);
        //y->count = x->count;
    }
    free(x->word);
    free(x);
    return t;
}
Exemple #2
0
char * lookup(tree * t, int key) {
    tree * x = Descend(t, key);
    if (x == NULL) {
        printf("loser\n");
        exit(1);
    }
    char * val = x->word;
    return val;
}
Exemple #3
0
//**************************************
// Find a subchunk with the pID identity
//**************************************
WORD  RIFFClass::FindCk(const CHAR* pID)
{
  DWORD dwID     = MAKE_ID(pID);

  Reset();
  ReadCkHdr();

  while (TRUE)
  {
	 if ((dwID == dwLastID) ||        // We found our chunk
	(dwID == dwLastFormID))
		return (SUCCESS);
	 else if (Descend() != SUCCESS)
	 {
		if (Ascend() != SUCCESS)       // Jump to the next chunk
	break;
	 }
  }
  return (RIFF_FINDERROR);
}
Exemple #4
0
Node * buildST(int numberOfStrings) {
	root = initNode();
	previouslyNode = root;
	Node *sentinel = initNode();
	root->slink = sentinel;
	root->hook = &(sentinel->child);
	sentinel->child = root;
	sentinel->sdep = -1;
	Point *p = malloc(sizeof(Point));
	p->a = root;
	p->b = root;
	int i = 0;
	while (i < numberOfStrings) {
		p->s = 0;
		int j = 0;
		Ti[i][ni[i]] = '!';
		while (j <= ni[i]) {
			while (!DescendQ(p, Ti[i][j])) {
				AddLeaf(p, i, j);

				SuffixLink(p);
			}
			Descend(p);
			j++;
		}
		Ti[i][ni[i]] = '-';
		i++;
		p->a = root;
		p->b = root;
		previouslySplit = NULL;
		previouslyNode = root;
	}
	free(p);
	free(sentinel);
	return root;
}
Exemple #5
0
int CWaveFile::UpdateHeader( void )
/////////////////////////////////////////////////////////////////////////////
{
	MMRESULT Result;

	// ascend out of the data subchunk
	Result = Ascend( &m_mmckinfoSubchunk );
	if( Result )
		DPF(("UpdateHeader: Ascend data subchunk failed!\n"));
	//DPF(("fccType [%08lx] %lu\n", m_mmckinfoSubchunk.fccType, m_mmckinfoSubchunk.cksize ));

	// ascend out of the WAVE chunk, which automaticlly updates the cksize field
	Result = Ascend( &m_mmckinfoParent );
	if( Result )
		DPF(("UpdateHeader: Ascend WAVE chunk failed %ld!\n", Result ));
	//DPF(("fccType [%08lx] %lu\n", m_mmckinfoParent.fccType, m_mmckinfoParent.cksize ));

	//MMSYSERR_INVALPARAM 
	// force write to disk
	Result = Flush( MMIO_EMPTYBUF );
	if( Result )
		DPF(("UpdateHeader: Flush failed!\n"));

	// if a compressed format, then update the fact chunk
	if( m_FormatEx.wFormatTag != WAVE_FORMAT_PCM )
	{
		DWORD		dwSampleLength;
		MMCKINFO	mmckinfoFact;

		// move to start of file
		SeekBegin( 0 );

		// find the WAVE chunk
		m_mmckinfoParent.fccType = mmioFOURCC('W','A','V','E');
		if( Descend( (LPMMCKINFO)&m_mmckinfoParent, NULL, MMIO_FINDRIFF ) )
		{
			Close();
			return( FALSE );
		}

		// Now, find the fact chunk 
		mmckinfoFact.ckid = mmioFOURCC('f','a','c','t');
		if( Descend( &mmckinfoFact, &m_mmckinfoParent, MMIO_FINDCHUNK ) )
		{
			Close();
			return( FALSE );
		}

		// compute out the number of samples
		dwSampleLength = GetSampleCount();

		// write the fact chunk
		if( Write( (HPSTR)&dwSampleLength, sizeof( DWORD )) != (LONG)sizeof( DWORD ) )
		{
			Close();
			return( FALSE );
		}

		// Ascend out of the fact subchunk.
		if( Ascend( &mmckinfoFact ) )
			DPF(("Ascend Failed\n"));
		// Ascend out of the WAVE chunk.
		if( Ascend( &m_mmckinfoParent ) )
			DPF(("Ascend Failed\n"));
	}

	return( TRUE );
}
Exemple #6
0
int CWaveFile::ReadHeader( void )
/////////////////////////////////////////////////////////////////////////////
{
	// Locate a 'RIFF' chunk with a 'WAVE' form type to make sure it's a WAVE file.
	m_mmckinfoParent.fccType = mmioFOURCC('W','A','V','E');
	if( Descend( &m_mmckinfoParent, NULL, MMIO_FINDRIFF ) )
	{
		DPF(("Cannot Descend into WAVE chunk!\n"));
		Close();
		return( FALSE );
	}

	// Now, find the format chunk (form type 'fmt '). It should be a subchunk of the 'RIFF' parent chunk.
	m_mmckinfoSubchunk.ckid = mmioFOURCC('f','m','t',' ');
	if( Descend( &m_mmckinfoSubchunk, &m_mmckinfoParent, MMIO_FINDCHUNK ) )
	{
		DPF(("Cannot find format chunk!\n"));
		Close();
		return( FALSE );
	}

	// Get the size of the format chunk
	m_lFormatSize = m_mmckinfoSubchunk.cksize;

	// read the format chunk
	if( Read( (HPSTR)&m_FormatEx, m_lFormatSize ) != (LONG)m_lFormatSize )
	{
		DPF(("Cannot read format chunk!\n"));
		Close();
		return( FALSE );
	}

	// Ascend out of the format subchunk.
	if( Ascend( &m_mmckinfoSubchunk ) )
	{
		DPF(("Ascend format subchunk failed!\n"));
	}

	// Find the data subchunk.
	m_mmckinfoSubchunk.ckid = mmioFOURCC('d','a','t','a');
	if( Descend( &m_mmckinfoSubchunk, &m_mmckinfoParent, MMIO_FINDCHUNK ) )
	{
		DPF(("Cannot Descend into data subchunk!\n"));
		Close();
		return( FALSE );
	}

	// Get the size of the data subchunk.
	m_dwDataSize = m_mmckinfoSubchunk.cksize;
	//DPF(("Data Size is %ld\n", m_dwDataSize ));
	
	// round file to integral number of audio blocks
	if( m_FormatEx.nBlockAlign )
		m_dwDataSize = (m_dwDataSize / m_FormatEx.nBlockAlign ) * m_FormatEx.nBlockAlign;

	//DPF(("Computed Data Size is %ld\n", m_dwDataSize ));

	if( m_dwDataSize == 0L )
	{
		DPF(("DataSize is zero!\n"));
		Close();
		return( FALSE );
	}

	m_dwBytesRead = 0;

	return( TRUE );
}