English 中文(简体)
String Buildinger vs Lists
原标题:String Builder vs Lists

我正在用多份卷宗阅读,有数百万条线。 我正在编制一份列有所有线性数字的清单,其中涉及一个具体问题。 例如,如果某个具体领域留空白或含有无效价值。

因此,我的问题是,跟踪人数清单的最有效率的日期类型,可以向上增加数百万人。 使用强硬建筑、清单或其它东西是否会提高效率?

我的最终目标是发出诸如“特定领域在1-32、40、45、47、49-51等空白”的信息。 因此,就“强硬建筑公司”而言,我会检查以前的价值,如果再看一看,我将从1到2,如果单单单单单单单单单单单单单单单单单单单单单单单单单单单单单。 随名单,我只想在名单上增加每个编号,然后在档案被彻底阅读后合并。 然而,在这种情况下,我可以有数百万人的名单。

这里,我正在使用现行法典,把使用“强硬建筑”的人数清单结合起来:

string currentLine = sbCurrentLineNumbers.ToString();
string currentLineSub;

StringBuilder subCurrentLine = new StringBuilder();
StringBuilder subCurrentLineSub = new StringBuilder();

int indexLastSpace = currentLine.LastIndexOf(   );
int indexLastDash = currentLine.LastIndexOf( - );

int currentStringInt = 0;

if (sbCurrentLineNumbers.Length == 0)
{
    sbCurrentLineNumbers.Append(lineCount);
}
else if (indexLastSpace == -1 && indexLastDash == -1)
{
    currentStringInt = Convert.ToInt32(currentLine);

    if (currentStringInt == lineCount - 1)
        sbCurrentLineNumbers.Append("-" + lineCount);
    else
    {
        sbCurrentLineNumbers.Append(", " + lineCount);
        commaCounter++;
    }
}
else if (indexLastSpace > indexLastDash)
{
    currentLineSub = currentLine.Substring(indexLastSpace);
    currentStringInt = Convert.ToInt32(currentLineSub);

    if (currentStringInt == lineCount - 1)
        sbCurrentLineNumbers.Append("-" + lineCount);
    else
    {
        sbCurrentLineNumbers.Append(", " + lineCount);
        commaCounter++;
    }
}
else if (indexLastSpace < indexLastDash)
{
    currentLineSub = currentLine.Substring(indexLastDash + 1);
    currentStringInt = Convert.ToInt32(currentLineSub);

    string charOld = currentLineSub;
    string charNew = lineCount.ToString();

    if (currentStringInt == lineCount - 1)
        sbCurrentLineNumbers.Replace(charOld, charNew);
    else
    {
        sbCurrentLineNumbers.Append(", " + lineCount);
        commaCounter++;
    }
}   
最佳回答

我的最终目标是发出诸如“特定领域在1-32、40、45、47、49-51上的空白”的信息。

如果达到最终目标,则通过中间人代表,例如<代码>List<int>——仅使用<代码>StringBuilder。 你们将节省记忆,万国邮联这样做。

问题回答

斯特凡德为你的目的服务,这样,如果你需要一定数量的话,你可以很容易地修改守则。

取决于你如何打破法典。

Given you are reading it in line order, not sure you need a list at all. Your current desired output implies that you can t output anything until the file is completely scanned. The size of the file suggests a one pass`analysis phase would be a good idea as well, given you are going to use buffered input as opposed to reading the entire thing into memory.

I d be tempted with an enum to describe the issue e.g Field??? is blank and then use that as the key a dictionary of string builders.

第一次思考

正如其他人所指出的,我可能使用<代码>StringBuilder。 清单可能不得不<><>resize<>strong>多次;<代码>新实施不必重现。

Is your output supposed to be human readable? If so, you ll hit the limit of what is reasonable to read, long before you have any performance/memory issues from your data structure. Use whatever is easiest for you to work with.

如果该产出本应是机器可读的,那么该产出可能意味着适当的数据结构。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签