From bd6976cd62cf325c62cd57a1aeb5b100aac66a17 Mon Sep 17 00:00:00 2001 From: krymtkts Date: Sat, 25 Jan 2025 23:29:17 +0900 Subject: [PATCH] Remove unused index from `PropertySearch.Rotate`. --- src/pocof.Benchmark/Benchmarks.fs | 2 +- src/pocof.Test/Handle.fs | 49 +++++++++++++------------------ src/pocof.Test/Query.fs | 4 +-- src/pocof/Data.fs | 2 +- src/pocof/Handle.fs | 10 +++---- src/pocof/Query.fs | 2 +- 6 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/pocof.Benchmark/Benchmarks.fs b/src/pocof.Benchmark/Benchmarks.fs index d41d696..66daceb 100644 --- a/src/pocof.Benchmark/Benchmarks.fs +++ b/src/pocof.Benchmark/Benchmarks.fs @@ -111,7 +111,7 @@ type HandleBenchmarks() = { state with InternalState.QueryState.Query = ":Name" InternalState.QueryState.Cursor = 5 - PropertySearch = PropertySearch.Rotate("Na", 0, Seq.cycle [ "Name"; "Names" ]) } + PropertySearch = PropertySearch.Rotate("Na", Seq.cycle [ "Name"; "Names" ]) } let context, _ = state |> Query.prepare diff --git a/src/pocof.Test/Handle.fs b/src/pocof.Test/Handle.fs index 86a7afe..0c4b247 100644 --- a/src/pocof.Test/Handle.fs +++ b/src/pocof.Test/Handle.fs @@ -1864,11 +1864,10 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "" - b |> shouldEqual 0 - c + b |> Seq.take 4 |> List.ofSeq |> shouldEqual [ "first"; "second"; "third"; "first" ] @@ -1892,10 +1891,9 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "p" - b |> shouldEqual 0 - c |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "Path"; "Path" ] + b |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "Path"; "Path" ] | _ -> failwith "PropertySearch should be Rotate" a2.Queries |> testQueryEnd @@ -1918,10 +1916,9 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "n" - b |> shouldEqual 0 - c |> Seq.take 3 |> List.ofSeq |> shouldEqual [ "name"; "number"; "name" ] + b |> Seq.take 3 |> List.ofSeq |> shouldEqual [ "name"; "number"; "name" ] | _ -> failwith "PropertySearch should be Rotate" a2.Queries |> testQueryEnd @@ -1942,10 +1939,9 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "n" - b |> shouldEqual 0 - c |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "name"; "name" ] + b |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "name"; "name" ] | _ -> failwith "PropertySearch should be Rotate" a2.Queries |> testQueryPartProperty "name" "foo" @@ -1966,10 +1962,9 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "name" - b |> shouldEqual 0 - c |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "name"; "name" ] + b |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "name"; "name" ] | _ -> failwith "PropertySearch should be Rotate" a2.Queries |> testQueryEnd @@ -1990,10 +1985,9 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "name" - b |> shouldEqual 0 - c |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "name"; "name" ] + b |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "name"; "name" ] | _ -> failwith "PropertySearch should be Rotate" a2.Queries |> testQueryPartProperty "name" "a" @@ -2014,10 +2008,9 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "nam" - b |> shouldEqual 0 - c |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "name"; "name" ] + b |> Seq.take 2 |> List.ofSeq |> shouldEqual [ "name"; "name" ] | _ -> failwith "PropertySearch should be Rotate" a2.Queries |> testQueryPartProperty "name" "a" @@ -2028,7 +2021,7 @@ module invokeAction = { state with InternalState.QueryState.Query = ":name" InternalState.QueryState.Cursor = 5 - PropertySearch = PropertySearch.Rotate("n", 0, Seq.cycle [ "name"; "number" ]) } + PropertySearch = PropertySearch.Rotate("n", Seq.cycle [ "name"; "number" ]) } let context, _ = Query.prepare state @@ -2040,10 +2033,9 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "n" - b |> shouldEqual 0 - c |> Seq.take 3 |> List.ofSeq |> shouldEqual [ "number"; "name"; "number" ] + b |> Seq.take 3 |> List.ofSeq |> shouldEqual [ "number"; "name"; "number" ] | _ -> failwith "PropertySearch should be Rotate" a2.Queries |> testQueryEnd @@ -2054,7 +2046,7 @@ module invokeAction = { state with InternalState.QueryState.Query = ":number" InternalState.QueryState.Cursor = 7 - PropertySearch = PropertySearch.Rotate("n", 0, Seq.cycle [ "number"; "name" ]) } + PropertySearch = PropertySearch.Rotate("n", Seq.cycle [ "number"; "name" ]) } let context, _ = Query.prepare state @@ -2066,10 +2058,9 @@ module invokeAction = a1.PropertySearch |> function - | PropertySearch.Rotate(a, b, c) -> + | PropertySearch.Rotate(a, b) -> a |> shouldEqual "n" - b |> shouldEqual 0 - c |> Seq.take 3 |> List.ofSeq |> shouldEqual [ "name"; "number"; "name" ] + b |> Seq.take 3 |> List.ofSeq |> shouldEqual [ "name"; "number"; "name" ] | _ -> failwith "PropertySearch should be Rotate" a2.Queries |> testQueryEnd diff --git a/src/pocof.Test/Query.fs b/src/pocof.Test/Query.fs index 9aa6c1b..ec54492 100644 --- a/src/pocof.Test/Query.fs +++ b/src/pocof.Test/Query.fs @@ -106,7 +106,7 @@ module props = Query.props properties { state with - PropertySearch = Data.PropertySearch.Rotate("", 0, [ "Name" ]) } + PropertySearch = Data.PropertySearch.Rotate("", [ "Name" ]) } |> shouldEqual (Ok [ "Name"; "Attribute"; "Length" ]) [] @@ -114,7 +114,7 @@ module props = Query.props properties { state with - PropertySearch = Data.PropertySearch.Rotate("Na", 0, [ "Name" ]) } + PropertySearch = Data.PropertySearch.Rotate("Na", [ "Name" ]) } |> shouldEqual (Ok [ "Name" ]) module run = diff --git a/src/pocof/Data.fs b/src/pocof/Data.fs index c5b1c7c..299a34e 100644 --- a/src/pocof/Data.fs +++ b/src/pocof/Data.fs @@ -265,7 +265,7 @@ module Data = type PropertySearch = | NoSearch | Search of keyword: string - | Rotate of keyword: string * index: int * candidates: string seq + | Rotate of keyword: string * candidates: string seq [] [] diff --git a/src/pocof/Handle.fs b/src/pocof/Handle.fs index 08dcb9f..d8615be 100644 --- a/src/pocof/Handle.fs +++ b/src/pocof/Handle.fs @@ -314,12 +314,12 @@ module Handle = | AlreadyCompleted keyword tail rest -> basePosition, head, rest | _ -> basePosition, head, tail - let buildValues head next tail keyword i candidates basePosition = + let buildValues head next tail keyword candidates basePosition = let state = { state with InternalState.QueryState.Query = $"%s{head}%s{next}%s{tail}" InternalState.QueryState.Cursor = basePosition + String.length next - PropertySearch = PropertySearch.Rotate(keyword, i, candidates) } + PropertySearch = PropertySearch.Rotate(keyword, candidates) } |> InternalState.refresh state, context |> QueryContext.prepareQuery state @@ -337,8 +337,8 @@ module Handle = #if DEBUG Logger.LogFile [ $"Search keyword '{keyword}' head '{head}' candidate '{candidate}' tail '{tail}'" ] #endif - buildValues head candidate tail keyword 0 (candidates |> Seq.cycle) basePosition - | PropertySearch.Rotate(keyword, _, candidates) -> + buildValues head candidate tail keyword (candidates |> Seq.cycle) basePosition + | PropertySearch.Rotate(keyword, candidates) -> let cur = candidates |> Seq.head let candidates = candidates |> Seq.tail let next = candidates |> Seq.head @@ -346,7 +346,7 @@ module Handle = #if DEBUG Logger.LogFile [ $"Rotate keyword '{keyword}' head '{head}' cur '{cur}' next '{next}' tail '{tail}'" ] #endif - buildValues head next tail keyword 0 candidates basePosition + buildValues head next tail keyword candidates basePosition let invokeAction (wordDelimiters: string) diff --git a/src/pocof/Query.fs b/src/pocof/Query.fs index 76fc025..e76ef1e 100644 --- a/src/pocof/Query.fs +++ b/src/pocof/Query.fs @@ -199,7 +199,7 @@ module Query = | _ -> match state.SuppressProperties, state.PropertySearch with | false, PropertySearch.Search(prefix: string) - | false, PropertySearch.Rotate(prefix: string, _, _) -> + | false, PropertySearch.Rotate(prefix: string, _) -> let ret = properties |> Seq.filter (String.startsWithIgnoreCase prefix) match ret |> Seq.length with