【发布时间】:2015-10-15 10:53:31
【问题描述】:
在某个软件上测试运行后,我试图解析一个非常大的日志文本文件(100 000 行以上)。为了做到这一点,我将文件划分为 1000 行的窗口,并在我们的测试运行中为每个测试递增地读取每个窗口。当我读完这 1000 行时,为了确保我不会再解析它们,我想将一个布尔值设置为 true,这意味着我应该跳过那个窗口,因为我确信我已经完成了解析它.
这是我迄今为止想出的:
...
let windowedAMLogSeq = Seq.windowed 1000 fullAMLogSeq
|> Seq.map (fun (window:string[]) -> (window , false))
for category in sortedTrxFailedTests do
for failedTest in category do
...
match failedTest.StartTime with
| Some x ->
match failedTest.EndTime with
| Some y ->
let accessManagerLogLines = parseAccessManagerLogFile x y windowedAMLogSeq
...
与
let parseAccessManagerLogFile (testStartTime:DateTime) (testEndTime:DateTime) (windowedAMLogSeq:seq<string[] * bool>) =
Seq.map (parseWindow testStartTime testEndTime) windowedAMLogSeq
和
let parseWindow testStartTime testEndTime (window:(string[] * bool)) =
match (snd window) with
| true ->
[||]
| false ->
let lineArray = Array.map (fun (line:string) -> if (isBetweenStartAndEndTime testStartTime testEndTime line) then line else "") (fst window)
let cleansedArray = Array.partition (fun (line:string) -> line <> "") lineArray
|> fst
match cleansedArray.Length > 0 with
| true ->
()
| false ->
window <- ((fst window), true) // Problem here, not mutable or by ref
cleansedArray
显然,这不会编译,因为window 不可变或通过引用传递。我尝试了多种使用 mutable 和 ref 或 byref 关键字的组合,但没有成功。作为 F# 的新手,我不确定要使用的正确语法。
为了通过引用直接修改window 值,或者能够通过引用window 元组中的布尔值来修改,使用什么语法?
【问题讨论】:
标签: .net reference f# tuples pass-by-reference