Skip to content

Commit

Permalink
Remove unused index from PropertySearch.Rotate.
Browse files Browse the repository at this point in the history
  • Loading branch information
krymtkts committed Jan 25, 2025
1 parent 0db79d4 commit bd6976c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/pocof.Benchmark/Benchmarks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
49 changes: 20 additions & 29 deletions src/pocof.Test/Handle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
4 changes: 2 additions & 2 deletions src/pocof.Test/Query.fs
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ module props =
Query.props
properties
{ state with
PropertySearch = Data.PropertySearch.Rotate("", 0, [ "Name" ]) }
PropertySearch = Data.PropertySearch.Rotate("", [ "Name" ]) }
|> shouldEqual (Ok [ "Name"; "Attribute"; "Length" ])

[<Fact>]
let ``should return Ok with filtered properties when rotate.`` () =
Query.props
properties
{ state with
PropertySearch = Data.PropertySearch.Rotate("Na", 0, [ "Name" ]) }
PropertySearch = Data.PropertySearch.Rotate("Na", [ "Name" ]) }
|> shouldEqual (Ok [ "Name" ])

module run =
Expand Down
2 changes: 1 addition & 1 deletion src/pocof/Data.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

[<RequireQualifiedAccess>]
[<NoComparison>]
Expand Down
10 changes: 5 additions & 5 deletions src/pocof/Handle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -337,16 +337,16 @@ 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
let basePosition, head, tail = splitQuery cur next
#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)
Expand Down
2 changes: 1 addition & 1 deletion src/pocof/Query.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bd6976c

Please sign in to comment.