Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
40371895
Commit
40371895
authored
Dec 29, 2010
by
Srikanth Raju
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ML: Use bsearch() instead of reinventing
parent
30834428
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
19 deletions
+14
-19
modules/media_library/sql_media_library.c
modules/media_library/sql_media_library.c
+14
-19
No files found.
modules/media_library/sql_media_library.c
View file @
40371895
...
@@ -60,9 +60,15 @@ static int CreateInputItemFromMedia( media_library_t *p_ml,
...
@@ -60,9 +60,15 @@ static int CreateInputItemFromMedia( media_library_t *p_ml,
struct
ml_table_elt
struct
ml_table_elt
{
{
int
column_id
;
int
column_id
;
char
column_name
[
20
]
;
char
*
column_name
;
};
};
static
int
compare_ml_elts
(
const
void
*
a
,
const
void
*
b
)
{
return
strcmp
(
(
(
struct
ml_table_elt
*
)
a
)
->
column_name
,
(
(
struct
ml_table_elt
*
)
b
)
->
column_name
);
}
static
const
struct
ml_table_elt
ml_table_map
[]
=
static
const
struct
ml_table_elt
ml_table_map
[]
=
{
{
{
ML_ALBUM_COVER
,
"album_cover"
},
{
ML_ALBUM_COVER
,
"album_cover"
},
...
@@ -479,26 +485,15 @@ int SQLToMediaArray( media_library_t *p_ml, vlc_array_t *p_result_array,
...
@@ -479,26 +485,15 @@ int SQLToMediaArray( media_library_t *p_ml, vlc_array_t *p_result_array,
const
int
count
=
sizeof
(
ml_table_map
)
/
sizeof
(
struct
ml_table_elt
);
const
int
count
=
sizeof
(
ml_table_map
)
/
sizeof
(
struct
ml_table_elt
);
for
(
int
col
=
0
;
col
<
i_cols
;
col
++
)
for
(
int
col
=
0
;
col
<
i_cols
;
col
++
)
{
{
//binary search
struct
ml_table_elt
key
,
*
result
=
NULL
;
int
low
=
0
,
high
=
count
-
1
;
key
.
column_name
=
res
(
0
,
col
);
int
answer
=
-
1
;
result
=
bsearch
(
&
key
,
ml_table_map
,
count
,
while
(
low
<=
high
)
{
sizeof
(
struct
ml_table_elt
),
compare_ml_elts
);
int
mid
=
(
low
+
high
)
/
2
;
char
*
mid_val
=
ml_table_map
[
mid
].
column_name
;
if
(
!
result
)
int
cmp
=
strcmp
(
mid_val
,
res
(
0
,
col
)
);
if
(
cmp
<
0
)
low
=
mid
+
1
;
else
if
(
cmp
>
0
)
high
=
mid
-
1
;
else
{
answer
=
mid
;
break
;
}
}
if
(
answer
==
-
1
)
msg_Warn
(
p_ml
,
"unknown column: %s"
,
res
(
0
,
col
)
);
msg_Warn
(
p_ml
,
"unknown column: %s"
,
res
(
0
,
col
)
);
else
else
indexes
[
col
]
=
ml_table_map
[
answer
].
column_id
;
indexes
[
col
]
=
result
->
column_id
;
}
}
/* Read rows 1 to i_rows */
/* Read rows 1 to i_rows */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment