Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F131417
sorter.hpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
sorter.hpp
View Options
#pragma once
#include
"./fuzzy_match.hpp"
#include
"./match.hpp"
#include
"./thread_pool.hpp"
namespace
ivy
{
class
Sorter
{
ivy
::
ThreadPool
m_thread_pool
;
std
::
string_view
m_term
;
std
::
mutex
m_matches_lock
;
std
::
vector
<
Match
>
m_matches
;
inline
void
add_entry
(
const
std
::
string
&
file
)
{
ivy
::
FuzzyMatcher
matcher
(
m_term
,
0
);
int
score
=
matcher
.
match
(
file
,
false
);
if
(
score
>
-200
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_matches_lock
);
m_matches
.
emplace_back
(
Match
{
score
,
std
::
move
(
file
)});
}
}
public
:
explicit
Sorter
(
std
::
string_view
term
)
:
m_term
(
term
)
{}
~
Sorter
()
{
m_thread_pool
.
shutdown
();
}
inline
std
::
vector
<
Match
>
sort
(
const
std
::
vector
<
std
::
string
>&
list
)
{
for
(
const
std
::
string
&
item
:
list
)
{
m_thread_pool
.
push
([
&
item
,
this
]()
{
add_entry
(
item
);
});
}
while
(
!
m_thread_pool
.
empty
())
{
// Wait for all of the jobs to be finished
}
std
::
sort
(
m_matches
.
begin
(),
m_matches
.
end
(),
sort_match
);
return
m_matches
;
}
};
}
// namespace ivy
File Metadata
Details
Attached
Mime Type
text/x-c++
Expires
Apr 6 2026, 5:52 PM (5 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16096
Default Alt Text
sorter.hpp (1 KB)
Attached To
Mode
R1 ivy.nvim
Attached
Detach File
Event Timeline
Log In to Comment