mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-10 08:44:20 +02:00
use for directly
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
use <../../util/slice.scad>;
|
||||
use <../../util/sum.scad>;
|
||||
|
||||
function _m_determinant_sub(matrix, leng, fc) =
|
||||
let(
|
||||
init_sub_m = [for(i = [1:leng - 1]) matrix[i]],
|
||||
sub_m = [for(i = [0:len(init_sub_m) - 1])
|
||||
concat(slice(init_sub_m[i], 0, fc), slice(init_sub_m[i], fc + 1))
|
||||
let(
|
||||
mi = init_sub_m[i],
|
||||
leng_mi = len(mi)
|
||||
)
|
||||
[for(j = 0; j < leng_mi; j = j + 1) if(j != fc) mi[j]]
|
||||
|
||||
],
|
||||
sgn = pow(-1, fc % 2)
|
||||
)
|
||||
|
@@ -1,5 +1,3 @@
|
||||
|
||||
use <../slice.scad>;
|
||||
use <../some.scad>;
|
||||
|
||||
function _dedup(elems, leng, buckets, eq, hash, bucket_numbers, i = 0) =
|
||||
@@ -15,8 +13,6 @@ function _dedup_add(buckets, i_elem, eq, hash, bucket_numbers) =
|
||||
)
|
||||
some(bucket, function(i_e) eq(i_e[1], elem)) ? buckets : _add(buckets, bucket, i_elem, b_idx);
|
||||
|
||||
function _add(buckets, bucket, i_elem, b_idx) = concat(
|
||||
slice(buckets, 0, b_idx),
|
||||
[concat(bucket, [i_elem])],
|
||||
slice(buckets, b_idx + 1)
|
||||
);
|
||||
function _add(buckets, bucket, i_elem, b_idx) =
|
||||
let(leng = len(buckets))
|
||||
[for(i = 0; i < leng; i = i + 1) i == b_idx ? concat(bucket, [i_elem]) : buckets[i]];
|
@@ -1,4 +1,3 @@
|
||||
use <../../slice.scad>;
|
||||
use <../../some.scad>;
|
||||
use <../../find_index.scad>;
|
||||
|
||||
@@ -13,20 +12,12 @@ function _hashmap_put(map, key, value, eq, hash) =
|
||||
|
||||
function _replace(map, bucket, key, value, b_idx, k_idx) =
|
||||
let(
|
||||
n_bucket = concat(
|
||||
slice(bucket, 0, k_idx),
|
||||
[[key, value]],
|
||||
slice(bucket, k_idx + 1)
|
||||
)
|
||||
leng_bucket = len(bucket),
|
||||
n_bucket = [for(i = 0; i < leng_bucket; i = i + 1) i == k_idx ? [key, value] : bucket[i]],
|
||||
leng_map = len(map)
|
||||
)
|
||||
concat(
|
||||
slice(map, 0, b_idx),
|
||||
[n_bucket],
|
||||
slice(map, b_idx + 1)
|
||||
);
|
||||
[for(i = 0; i < leng_map; i = i + 1) i == b_idx ? n_bucket : map[i]];
|
||||
|
||||
function _put(map, bucket, key, value, b_idx) = concat(
|
||||
slice(map, 0, b_idx),
|
||||
[concat(bucket, [[key, value]])],
|
||||
slice(map, b_idx + 1)
|
||||
);
|
||||
function _put(map, bucket, key, value, b_idx) =
|
||||
let(leng_map = len(map))
|
||||
[for(i = 0; i < leng_map; i = i + 1) i == b_idx ? concat(bucket, [[key, value]]) : map[i]];
|
@@ -9,20 +9,20 @@
|
||||
**/
|
||||
|
||||
use <../../__comm__/_str_hash.scad>;
|
||||
use <../slice.scad>;
|
||||
use <../find_index.scad>;
|
||||
|
||||
function hashmap_del(map, key, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) =
|
||||
let(
|
||||
bidx = hash(key) % len(map),
|
||||
bucket = map[bidx],
|
||||
leng = len(bucket)
|
||||
leng_bucket = len(bucket),
|
||||
leng_map = len(map)
|
||||
)
|
||||
leng == 0 ? map :
|
||||
leng_bucket == 0 ? map :
|
||||
let(i = find_index(bucket, function(e) eq(e[0], key)))
|
||||
i == -1 ? map :
|
||||
concat(
|
||||
slice(map, 0, bidx),
|
||||
[concat(slice(bucket, 0, i), slice(bucket, i + 1))],
|
||||
slice(map, bidx + 1)
|
||||
);
|
||||
[
|
||||
for(j = 0; j < leng_map; j = j + 1) j == bidx ?
|
||||
[for(k = 0; k < leng_bucket; k = k + 1) if(k != i) bucket[k]] :
|
||||
map[j]
|
||||
];
|
@@ -9,7 +9,6 @@
|
||||
**/
|
||||
|
||||
use <../../__comm__/_str_hash.scad>;
|
||||
use <../slice.scad>;
|
||||
use <../find_index.scad>;
|
||||
|
||||
function hashmap_get(map, key, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) =
|
||||
|
@@ -1,4 +1,3 @@
|
||||
use <../../slice.scad>;
|
||||
use <../../some.scad>;
|
||||
|
||||
function _hashset_add(set, elem, eq, hash) =
|
||||
@@ -8,8 +7,6 @@ function _hashset_add(set, elem, eq, hash) =
|
||||
)
|
||||
some(bucket, function(e) eq(e, elem)) ? set : _add(set, bucket, elem, idx);
|
||||
|
||||
function _add(set, bucket, elem, idx) = concat(
|
||||
slice(set, 0, idx),
|
||||
[concat(bucket, [elem])],
|
||||
slice(set, idx + 1)
|
||||
);
|
||||
function _add(set, bucket, elem, idx) =
|
||||
let(leng = len(set))
|
||||
[for(i = 0; i < leng; i = i + 1) i == idx ? concat(bucket, [elem]) : set[i]];
|
@@ -9,7 +9,6 @@
|
||||
**/
|
||||
|
||||
use <../../__comm__/_str_hash.scad>;
|
||||
use <../slice.scad>;
|
||||
use <../find_index.scad>;
|
||||
|
||||
function hashset_del(set, elem, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) =
|
||||
|
Reference in New Issue
Block a user