Click here to Skip to main content
14,301,484 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Pro Tip Pin
RickZeeland19-Jul-19 10:17
mveRickZeeland19-Jul-19 10:17 
GeneralRe: Pro Tip Pin
Mike Hankey19-Jul-19 10:18
professionalMike Hankey19-Jul-19 10:18 
GeneralRe: Pro Tip Pin
PIEBALDconsult19-Jul-19 10:27
protectorPIEBALDconsult19-Jul-19 10:27 
GeneralRe: Pro Tip Pin
Nelek19-Jul-19 10:51
protectorNelek19-Jul-19 10:51 
GeneralRe: Pro Tip Pin
dandy7219-Jul-19 11:18
memberdandy7219-Jul-19 11:18 
GeneralRe: Pro Tip Pin
Slacker00719-Jul-19 13:50
professionalSlacker00719-Jul-19 13:50 
GeneralRe: Pro Tip Pin
theoldfool19-Jul-19 14:47
professionaltheoldfool19-Jul-19 14:47 
GeneralThere is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 4:54
memberhoney the codewitch19-Jul-19 4:54 
Do you ever hate yourself a little for the code you write?

I'm writing some extremely destructive code at the moment

IList<IList<string>> _Explode(IList<IList<string>> left, IList<IList<string>> right)
{
	if (right.IsNullOrEmpty())
		return left;
	else if (left.IsNullOrEmpty())
		return right;
	var result = new List<IList<string>>();
	foreach (var leftList in left)
	{
		foreach (var rightList in right)
		{
			var finalList = new List<string>();
			finalList.AddRange(leftList);
			finalList.AddRange(rightList); ;
			if (!result.Contains(
				finalList, 
				OrderedCollectionEqualityComparer<string>.Default))
				result.Add(finalList);
		}
	}
	return result;
}

Its job apparently is to work my CPU like a rented mule while it eats up all my ram.

I am microsoft.

EDIT:

After some suggestions in the comments, it didn't make a big difference overall but I removed every foreach and added preallocation to the lists. Comments removed for brevity
IList<IList<string>> _Explode(IList<IList<string>> left, IList<IList<string>> right)
{
	if (null== right||0==right.Count)
		return left;
	else if (null==left||0==left.Count)
		return right;
	var result = new List<IList<string>>();
	for(int ic=left.Count,i=0;i<ic;++i)
	{
		var leftList = left[i];
		for(int jc=right.Count,j=0;j<jc;++j)
		{
			var rightList = right[j];
			var finalList = new List<string>(ic+jc);
			for(int kc=leftList.Count,k=0;k<kc;++k)
				finalList.Add(leftList[k]);
			for (int kc = rightList.Count, k = 0; k < kc; ++k)
				finalList.Add(rightList[k]);
			var oec = OrderedCollectionEqualityComparer<string>.Default;
			var found = false;
			for (int kc = result.Count, k = 0; k < kc; ++k)
			{
				if (oec.Equals(result[k], finalList))
				{
					found = true;
					break;
				}
			}
			if(!found)
				result.Add(finalList);
		}
	}
	return result;
}

When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.


modified 19-Jul-19 12:24pm.

GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
Ravi Bhavnani19-Jul-19 5:21
professionalRavi Bhavnani19-Jul-19 5:21 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 5:23
memberhoney the codewitch19-Jul-19 5:23 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
Richard Deeming19-Jul-19 5:32
mveRichard Deeming19-Jul-19 5:32 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 5:36
memberhoney the codewitch19-Jul-19 5:36 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
Richard Deeming19-Jul-19 5:44
mveRichard Deeming19-Jul-19 5:44 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 5:48
memberhoney the codewitch19-Jul-19 5:48 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
PIEBALDconsult19-Jul-19 5:33
protectorPIEBALDconsult19-Jul-19 5:33 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 5:38
memberhoney the codewitch19-Jul-19 5:38 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
PIEBALDconsult19-Jul-19 6:09
protectorPIEBALDconsult19-Jul-19 6:09 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 6:11
memberhoney the codewitch19-Jul-19 6:11 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
Richard Deeming19-Jul-19 5:35
mveRichard Deeming19-Jul-19 5:35 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 5:37
memberhoney the codewitch19-Jul-19 5:37 
JokeRe: There is no efficient way to do this, but I'm doing it anyway. Pin
Member 1433107619-Jul-19 5:46
memberMember 1433107619-Jul-19 5:46 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 5:47
memberhoney the codewitch19-Jul-19 5:47 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
Sander Rossel19-Jul-19 19:00
professionalSander Rossel19-Jul-19 19:00 
GeneralRe: There is no efficient way to do this, but I'm doing it anyway. Pin
honey the codewitch19-Jul-19 21:49
memberhoney the codewitch19-Jul-19 21:49 
GeneralThought of the Day Pin
OriginalGriff19-Jul-19 4:39
protectorOriginalGriff19-Jul-19 4:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.