From 233ae4b50a9d7263c3d1bb56e760a81b3c0d7301 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 11 Apr 2022 11:08:12 +0800 Subject: [PATCH] refactor: extract a template --- src/util/_impl/_find_eq_search_some.scad | 11 +++++++++++ src/util/map/_impl/_hashmap_impl.scad | 12 +----------- 2 files changed, 12 insertions(+), 11 deletions(-) create mode 100644 src/util/_impl/_find_eq_search_some.scad diff --git a/src/util/_impl/_find_eq_search_some.scad b/src/util/_impl/_find_eq_search_some.scad new file mode 100644 index 00000000..aa709c11 --- /dev/null +++ b/src/util/_impl/_find_eq_search_some.scad @@ -0,0 +1,11 @@ +_find_eq_search = function(lt, target, eq) + let(found = search([target], lt)[0]) + found == [] ? -1 : found; + +_find_eq_some = function(lt, target, eq) + let( + leng = len(lt), + indices = [for(i = 0; i < leng && !eq(lt[i], target); i = i + 1) undef], + leng_indices = len(indices) + ) + leng_indices == leng ? -1 : leng_indices; \ No newline at end of file diff --git a/src/util/map/_impl/_hashmap_impl.scad b/src/util/map/_impl/_hashmap_impl.scad index 50276db9..7e083183 100644 --- a/src/util/map/_impl/_hashmap_impl.scad +++ b/src/util/map/_impl/_hashmap_impl.scad @@ -1,16 +1,6 @@ use <_hashmap_put_impl.scad>; -_find_eq_search = function(lt, target, eq) - let(found = search([target], lt)[0]) - found == [] ? -1 : found; - -_find_eq_some = function(lt, target, eq) - let( - leng = len(lt), - indices = [for(i = 0; i < leng && !eq(lt[i], target); i = i + 1) undef], - leng_indices = len(indices) - ) - leng_indices == leng ? -1 : leng_indices; +include <../../_impl/_find_eq_search_some.scad>; function _hashmap(kv_lt, leng, buckets, b_numbers, eq, hash) = let(