1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-09-25 13:59:04 +02:00

use for directly

This commit is contained in:
Justin Lin
2021-04-23 21:56:13 +08:00
parent d18665329f
commit baf64e47b8
7 changed files with 27 additions and 41 deletions

View File

@@ -1,11 +1,15 @@
use <../../util/slice.scad>;
use <../../util/sum.scad>; use <../../util/sum.scad>;
function _m_determinant_sub(matrix, leng, fc) = function _m_determinant_sub(matrix, leng, fc) =
let( let(
init_sub_m = [for(i = [1:leng - 1]) matrix[i]], init_sub_m = [for(i = [1:leng - 1]) matrix[i]],
sub_m = [for(i = [0:len(init_sub_m) - 1]) 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) sgn = pow(-1, fc % 2)
) )

View File

@@ -1,5 +1,3 @@
use <../slice.scad>;
use <../some.scad>; use <../some.scad>;
function _dedup(elems, leng, buckets, eq, hash, bucket_numbers, i = 0) = 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); 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( function _add(buckets, bucket, i_elem, b_idx) =
slice(buckets, 0, b_idx), let(leng = len(buckets))
[concat(bucket, [i_elem])], [for(i = 0; i < leng; i = i + 1) i == b_idx ? concat(bucket, [i_elem]) : buckets[i]];
slice(buckets, b_idx + 1)
);

View File

@@ -1,4 +1,3 @@
use <../../slice.scad>;
use <../../some.scad>; use <../../some.scad>;
use <../../find_index.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) = function _replace(map, bucket, key, value, b_idx, k_idx) =
let( let(
n_bucket = concat( leng_bucket = len(bucket),
slice(bucket, 0, k_idx), n_bucket = [for(i = 0; i < leng_bucket; i = i + 1) i == k_idx ? [key, value] : bucket[i]],
[[key, value]], leng_map = len(map)
slice(bucket, k_idx + 1)
)
) )
concat( [for(i = 0; i < leng_map; i = i + 1) i == b_idx ? n_bucket : map[i]];
slice(map, 0, b_idx),
[n_bucket],
slice(map, b_idx + 1)
);
function _put(map, bucket, key, value, b_idx) = concat( function _put(map, bucket, key, value, b_idx) =
slice(map, 0, b_idx), let(leng_map = len(map))
[concat(bucket, [[key, value]])], [for(i = 0; i < leng_map; i = i + 1) i == b_idx ? concat(bucket, [[key, value]]) : map[i]];
slice(map, b_idx + 1)
);

View File

@@ -9,20 +9,20 @@
**/ **/
use <../../__comm__/_str_hash.scad>; use <../../__comm__/_str_hash.scad>;
use <../slice.scad>;
use <../find_index.scad>; use <../find_index.scad>;
function hashmap_del(map, key, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) = function hashmap_del(map, key, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) =
let( let(
bidx = hash(key) % len(map), bidx = hash(key) % len(map),
bucket = map[bidx], 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))) let(i = find_index(bucket, function(e) eq(e[0], key)))
i == -1 ? map : i == -1 ? map :
concat( [
slice(map, 0, bidx), for(j = 0; j < leng_map; j = j + 1) j == bidx ?
[concat(slice(bucket, 0, i), slice(bucket, i + 1))], [for(k = 0; k < leng_bucket; k = k + 1) if(k != i) bucket[k]] :
slice(map, bidx + 1) map[j]
); ];

View File

@@ -9,7 +9,6 @@
**/ **/
use <../../__comm__/_str_hash.scad>; use <../../__comm__/_str_hash.scad>;
use <../slice.scad>;
use <../find_index.scad>; use <../find_index.scad>;
function hashmap_get(map, key, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) = function hashmap_get(map, key, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) =

View File

@@ -1,4 +1,3 @@
use <../../slice.scad>;
use <../../some.scad>; use <../../some.scad>;
function _hashset_add(set, elem, eq, hash) = 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); some(bucket, function(e) eq(e, elem)) ? set : _add(set, bucket, elem, idx);
function _add(set, bucket, elem, idx) = concat( function _add(set, bucket, elem, idx) =
slice(set, 0, idx), let(leng = len(set))
[concat(bucket, [elem])], [for(i = 0; i < leng; i = i + 1) i == idx ? concat(bucket, [elem]) : set[i]];
slice(set, idx + 1)
);

View File

@@ -9,7 +9,6 @@
**/ **/
use <../../__comm__/_str_hash.scad>; use <../../__comm__/_str_hash.scad>;
use <../slice.scad>;
use <../find_index.scad>; use <../find_index.scad>;
function hashset_del(set, elem, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) = function hashset_del(set, elem, eq = function(e1, e2) e1 == e2, hash = function(e) _str_hash(e)) =