summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-23 13:35:25 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-23 13:35:25 +0200
commitfe46ad8a6af32a52889719a838ad7178605c1d3d (patch)
tree3feb94898be0b0342cb9e17e62a040f01137ee15
parent723e09d915f103fab6f0308d1f11502b72aced92 (diff)
Bookmarks: Finding a bookmark by URL
This needs a better lookup if there are tons of bookmarks.
-rw-r--r--src/bookmarks.c13
-rw-r--r--src/bookmarks.h1
2 files changed, 13 insertions, 1 deletions
diff --git a/src/bookmarks.c b/src/bookmarks.c
index 7e98fb27..f97ef0c6 100644
--- a/src/bookmarks.c
+++ b/src/bookmarks.c
@@ -54,7 +54,7 @@ static const char *fileName_Bookmarks_ = "bookmarks.txt";
54struct Impl_Bookmarks { 54struct Impl_Bookmarks {
55 iMutex *mtx; 55 iMutex *mtx;
56 int idEnum; 56 int idEnum;
57 iHash bookmarks; 57 iHash bookmarks; /* bookmark ID is the hash key */
58}; 58};
59 59
60iDefineTypeConstruction(Bookmarks) 60iDefineTypeConstruction(Bookmarks)
@@ -173,6 +173,17 @@ iBool filterTagsRegExp_Bookmarks(void *regExp, const iBookmark *bm) {
173 return matchString_RegExp(regExp, &bm->tags, &m); 173 return matchString_RegExp(regExp, &bm->tags, &m);
174} 174}
175 175
176static iBool matchUrl_(void *url, const iBookmark *bm) {
177 return equalCase_String(url, &bm->url);
178}
179
180uint32_t findUrl_Bookmarks(const iBookmarks *d, const iString *url) {
181 /* TODO: O(n), boo */
182 const iPtrArray *found = list_Bookmarks(d, NULL, matchUrl_, (void *) url);
183 if (isEmpty_PtrArray(found)) return 0;
184 return id_Bookmark(constFront_PtrArray(found));
185}
186
176const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp, 187const iPtrArray *list_Bookmarks(const iBookmarks *d, iBookmarksCompareFunc cmp,
177 iBookmarksFilterFunc filter, void *context) { 188 iBookmarksFilterFunc filter, void *context) {
178 lock_Mutex(d->mtx); 189 lock_Mutex(d->mtx);
diff --git a/src/bookmarks.h b/src/bookmarks.h
index 4889e7b5..84bdbd68 100644
--- a/src/bookmarks.h
+++ b/src/bookmarks.h
@@ -51,6 +51,7 @@ void save_Bookmarks (const iBookmarks *, const char *dirPath);
51void add_Bookmarks (iBookmarks *, const iString *url, const iString *title, const iString *tags, iChar icon); 51void add_Bookmarks (iBookmarks *, const iString *url, const iString *title, const iString *tags, iChar icon);
52iBool remove_Bookmarks (iBookmarks *, uint32_t id); 52iBool remove_Bookmarks (iBookmarks *, uint32_t id);
53iBookmark *get_Bookmarks (iBookmarks *, uint32_t id); 53iBookmark *get_Bookmarks (iBookmarks *, uint32_t id);
54uint32_t findUrl_Bookmarks (const iBookmarks *, const iString *url); /* O(n) */
54 55
55typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *); 56typedef iBool (*iBookmarksFilterFunc) (void *context, const iBookmark *);
56typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **); 57typedef int (*iBookmarksCompareFunc)(const iBookmark **, const iBookmark **);