Example #1
0
DWORD CItemList::AddItem( DWORD flags )
{
	// Is it a group?
	if ( ( flags & LIF_GROUP ) != 0 ) m_bInGroup = TRUE;
	if ( m_bInGroup ) flags |= LIF_INGROUP;
	else flags &= ~LIF_INGROUP;

	// Set group flag
	if ( m_bInGroup ) m_bGroups = TRUE;

	// Allocate memory
	LPLISTITEMINFO	plii = new LISTITEMINFO;
	if ( plii == NULL ) return MAXDWORD;

	// Initialize memory to zero
	ZeroMemory( plii, sizeof( LISTITEMINFO ) );

	// Save the index pointer
	plii->index = m_dwPtr;
	plii->height = m_dwDefaultHeight;
	plii->flags = flags;
	plii->subitems = 0;
	
	// Allocate memory for index
	AllocateIndex( m_dwPtr + 1 );

	// Add this block to the index
	m_pIndex[ m_dwPtr ] = plii;

	// Count a block
	m_dwPtr++;

	// Return the index
	return plii->index;
}
Example #2
0
void CLibraryMaps::OnFileAdd(CLibraryFile* pFile)
{
	BOOL bSkipStats = FALSE;
	if ( pFile->m_nIndex )
	{
		if ( CLibraryFile* pOld = LookupFile( pFile->m_nIndex ) )
		{
			if ( pOld != pFile )
			{
				pFile->m_nIndex = AllocateIndex();
				m_pIndexMap.SetAt( pFile->m_nIndex, pFile );
			}
			else
			{
				bSkipStats = TRUE;
			}
		}
		else
		{
			m_pIndexMap.SetAt( pFile->m_nIndex, pFile );
		}
	}
	else
	{
		pFile->m_nIndex = AllocateIndex();
		m_pIndexMap.SetAt( pFile->m_nIndex, pFile );
	}

	if ( pFile->IsAvailable() && ! bSkipStats )
	{
		m_nVolume += pFile->m_nSize;
		m_nFiles ++;
	}

	m_pNameMap.SetAt( pFile->GetNameLC(), pFile );

	if ( pFile->IsAvailable() )
	{
		CString strPath( pFile->GetPath() );
		ToLower( strPath );
		m_pPathMap.SetAt( strPath, pFile );
	}
	else if ( m_pDeleted.Find( pFile ) == NULL )
	{
		m_pDeleted.AddTail( pFile );
	}

	if ( pFile->m_oSHA1 )
	{
		CLibraryFile** pHash = &m_pSHA1Map[ pFile->m_oSHA1[ 0 ] & HASH_MASK ];
		pFile->m_pNextSHA1 = *pHash;
		*pHash = pFile;
	}

	if ( pFile->m_oTiger )
	{
		CLibraryFile** pHash = &m_pTigerMap[ pFile->m_oTiger[ 0 ] & HASH_MASK ];
		pFile->m_pNextTiger = *pHash;
		*pHash = pFile;
	}

	if ( pFile->m_oED2K )
	{
		CLibraryFile** pHash = &m_pED2KMap[ pFile->m_oED2K[ 0 ] & HASH_MASK ];
		pFile->m_pNextED2K = *pHash;
		*pHash = pFile;
	}

	if ( pFile->m_oBTH )
	{
		CLibraryFile** pHash = &m_pBTHMap[ pFile->m_oBTH[ 0 ] & HASH_MASK ];
		pFile->m_pNextBTH = *pHash;
		*pHash = pFile;
	}

	if ( pFile->m_oMD5 )
	{
		CLibraryFile** pHash = &m_pMD5Map[ pFile->m_oMD5[ 0 ] & HASH_MASK ];
		pFile->m_pNextMD5 = *pHash;
		*pHash = pFile;
	}
}
Example #3
0
void FilterB(int Tlen_, char *B_, int Qlen_, const FilterParams &FP, int Diameter,
  bool Comp)
	{
	if (Comp)
		Quit("-diameter requires -fwdonly (this needs to be fixed!)");

	SeqQ = B_;
	Tlen = Tlen_;
	Qlen = Qlen_;

	MinMatch = FP.SeedLength;
	MaxError = FP.SeedDiffs;
	TubeOffset = FP.TubeOffset;

	const int Kmask = pow4(k) - 1;

// Ukonnen's Lemma
	MinKmersPerHit = MinMatch + 1 - k*(MaxError + 1);

// Maximum distance between SeqQ positions of two k-mers in a match
// (More stringent bounds may be possible, but not a big problem
// if two adjacent matches get merged).
	MaxKmerDist = MinMatch - k;

	TubeWidth = TubeOffset + MaxError;

	if (TubeOffset < MaxError)
		{
		Log("TubeOffset < MaxError\n");
		exit(1);
		}
	if (MinKmersPerHit <= 0)
		{
		Log("MinKmersPerHit <= 0\n");
		exit(1);
		}

	MaxActiveTubes = (Tlen + TubeWidth - 1)/TubeOffset + 1;
	Tubes = all(TubeState, MaxActiveTubes);
	zero(Tubes, TubeState, MaxActiveTubes);

// Ticker tracks cycling of circular list of active tubes.
	int Ticker = TubeWidth;

// Initialize index to cover first window
	int StartKmerValidPos = 0;
	int EndKmerValidPos = 0;

	AllocateIndex(Diameter, k);
	const int KmerCount = Diameter - k + 1;

	int Start;
	int End;

	for (Start = 0; Start < KmerCount; ++Start)
		{
		int StartKmer = GetKmer(SeqQ, Start);
		AddToIndex(StartKmer, Start);
		}

#if	DEBUG
	ValidateIndex(SeqQ, 0, Diameter - k);
#endif

// Scan entire sequence.
// Start is coordinate of first base in first k-mer in sliding window
// End is coordinate of first base in last k-mer in sliding window
	Start = 0;
	End = Start + Diameter - k;

	int StartKmer = GetKmer(SeqQ, Start);
	if (StartKmer == -1)
		{
		StartKmer = 0;
		StartKmerValidPos = Start + k + 1;
		}
	int EndKmer = GetKmer(SeqQ, End);
	if (EndKmer == -1)
		{
		EndKmer = 0;
		EndKmerValidPos = End + k + 1;
		}
	for (; End < Qlen - k; ++Start, ++End)
		{
#if	DEBUG
		if (Start%10000 == 0)
			fprintf(stderr, "%d\n", Start);
		//if (Start%1000 == 0)
		//	ValidateIndex(SeqQ, Start, End);
#endif
		if (Start >= StartKmerValidPos)
			{
			assert(StartKmer == GetKmer(SeqQ, Start));
			for (DeclareListPtr(p) = GetListPtr(StartKmer); NotEndOfList(p); p = GetListNext(p))
				{
				int HitPos = GetListPos(p);
				CommonKmer(Start, HitPos);
				}
			DeleteFirstInstanceFromIndex(StartKmer, Start);
			}

		if (0 == --Ticker)
			{
			TubeEnd(Start);
			Ticker = TubeOffset;
			}

		{
		char c = SeqQ[Start + k];
		int x = CharToLetter[c];
		if (x < 0)
			{
			StartKmer = 0;
			StartKmerValidPos = Start + k + 1;
			}
		else
			StartKmer = ((StartKmer << 2) | x) & Kmask;
		}

		{
		char c = SeqQ[End + k];
		int x = CharToLetter[c];
		if (x < 0)
			{
			EndKmer = 0;
			EndKmerValidPos = End + k + 1;
			}
		else
			EndKmer = ((EndKmer << 2) | x) & Kmask;

		if (End+1 >= EndKmerValidPos)
			{
			assert(EndKmer == GetKmer(SeqQ, End+1));
			AddToIndex(EndKmer, End+1);
			}
		}
		}

#if	DEBUG
	ValidateIndex(SeqQ, Start, Qlen - k);
#endif

// Special case for end of sequence, don't slide the index
// for the last Diameter bases.
	for (; Start < Qlen - k; ++Start)
		{
		{
		char c = SeqQ[Start + k];
		int x = CharToLetter[c];
		if (x < 0)
			{
			StartKmer = 0;
			StartKmerValidPos = Start + k + 1;
			}
		else
			StartKmer = ((StartKmer << 2) | x) & Kmask;
		}

		if (Start >= StartKmerValidPos)
			{
			for (DeclareListPtr(p) = GetListPtr(StartKmer); NotEndOfList(p); p = GetListNext(p))
				{
				int HitPos = GetListPos(p);
				CommonKmer(Start, HitPos);
				}
			}

		if (0 == --Ticker)
			{
			TubeEnd(Start);
			Ticker = TubeOffset;
			}
		}

	TubeEnd(Qlen - 1);

	int DiagFrom = CalcDiagIndex(Tlen - 1, Qlen - 1) - TubeWidth;
	int DiagTo = CalcDiagIndex(0, Qlen - 1) + TubeWidth;

	int TubeFrom = CalcTubeIndex(DiagFrom);
	if (TubeFrom < 0)
		TubeFrom = 0;

	int TubeTo = CalcTubeIndex(DiagTo);

	for (int TubeIndex = TubeFrom; TubeIndex <= TubeTo; ++TubeIndex)
		TubeFlush(TubeIndex);

	freemem(Tubes);
	}