duangsuse::Echo
711 subscribers
4.24K photos
127 videos
583 files
6.44K links
import this:
美而不丑、明而不暗、短而不凡、长而不乱,扁平不宽,读而后码,行之天下,勿托地上天国。
异常勿吞,难过勿过,叹一真理。效率是很重要,盲目最是低效。
简明是可靠的先验,不是可靠的祭品。
知其变,守其恒,为天下式;穷其变,知不穷,得地上势。知变守恒却穷变知新,我认真理,我不认真。

技术相干订阅~
另外有 throws 闲杂频道 @dsuset
转载频道 @dsusep
极小可能会有批评zf的消息 如有不适可退出
suse小站(面向运气编程): https://WOJS.org/#/
Download Telegram
This media is not supported in your browser
VIEW IN TELEGRAM
duangsuse::Echo
如果可能的话还想写点 Rust extern 和 unsafe 的内容呢... btw. (其实是完全无关的)想自动内存管理的时候突然想到 Xor 的 HexagonVM 使用了一个比较 trivial 的 naive dfs tracing GC,内存分配是基于 Rust std 类型的 https://github.com/losfair/hexagon/blob/master/src/object_pool.rs#L143 /// Run the garbage collector with…
let ROOT_STATICS = 0usize;
fun visit_child(&mut self, &mut dfs: Vec<usize>, id: usize) {
let prod = &self.objects[id].as_ref().unwrap().as_object();
dfs.push_all(prod.get_children());
}

pub fn collect(&mut self, stack: &CallStack) {
let mut id_alive = vec![false; self.objects.len()];
let mut dfs: Vec<usize> = Vec::new();
dfs.push(ROOT_STATICS);

dfs.push_all(stack.collect_objects());
while let Some(id) = dfs.pop() {
if id_alive[id] { continue }
id_alive[id] = true;
self.visit_child(dfs, id);
}

for id in id_visited {
if !self.objects[id].is_some() || id_alive[id]
|| self.objects[id].as_ref().unwrap().has_native_refs()
{ continue }

self.objects[id].as_ref().unwrap().gc_notify();
self.deallocate(i);
}
}

Rust 的写起来相信会难看许多,因为它首先要 lifetime……(或许,如果推断不出的话)
然后是,我不知道 push_all 什么的能不能用
self.objects 居然是 Indexable<Optional<ProdVal>>, 也是奇怪,欸不对,是 index 这个操作本身 partial function…… 所以 Optional
不过 Rust 还是有自己的风格,但是到处 .as_ref().unwrap().…… ,还不如写该写的……

fun collectGarbage() {
val visited: MutableSet<ProdVal> = mutableSetOf() //....
}
This media is not supported in your browser
VIEW IN TELEGRAM
duangsuse::Echo
😊 Sticker
#home duangsuse 返校,哦不是回家快乐……

这次,我要完成的一些事情:

+ Zhuazhou 的细节修改,此外,为了代码复用,我还得完成 num_preety.js, stream.js 和 zhang.js 插件
+ Dokuss 的 unsigned write (Byte, Short, Char.uext; Int.byteIterator) 和 Doku 封装,(即将)重写
如果使用 Dokuss 的 Java class serializer 和 AXML serializer 都成功的话
+ Badge.dex 和 @builder kapt
+ RingBuffer 重写
+ Parser.kt (想了很久,也打了不少稿子)
+ Reflex (一门 JVM 脚本语言,送的,因为我正好需要解决 TypeEqualizer 没写出来的问题)
+ Montage.py (其实已经不重要了,因为之前的已经很多了…… 这个就是一个 DrawPlan, TintedDrawable, Range2D, Averager 和 samplePixel, colorInBound, ratioGT)

backgroundColor = hexcolor('#FFFFFF')
bound = (0x00, 0x00, 0x00)
shouldDrawText = compose(ratioGT(percent(50.0)), project(colorInBound(bound, backgroundColor)), samplePixel)

其中, project: ((Iterable<E>) -> R) -> (Iterable<E>) -> Pair<Iterable<E>, R>
RingBuffer.kt
3.8 KB
#Kotlin 我又写了一遍,不太好看,之前想的时候觉得是很清楚的,坐在屏幕前的时候就麻烦了
>>> listOf(1,2,3).zipWith(listOf(4,5,6)) { a,b->println("$a $b") }.take(2)
1 4
2 5
3 6
[kotlin.Unit, kotlin.Unit]
好像正常,为什么刚才测试的时候 addMany 好像不正确?
RingBuffer.kt
3.5 KB
我修改了一下代码,比如移除了不适合的类型抽象、改进了 until (新模型),现在看起来代码更好看了
用了常见的『Adapter』,解决了子类的麻烦,可是也感觉这有得有失
>>> r.addAll(listOf(1,2,3))
>>> r.viewport()
[1, 2, 3]
>>> r.pop()
1
>>> r.add(2)
>>> r.viewport()
[2, 3, 2]
>>> r
Ring[[2, 2, 3]; ^1, _1, 3]
好。
尽管我依然无法很好的在脑中『可视化』一个环,可是,我也能写出比较好看的代码了
RingBuffer.kt
4 KB
diff.kra
138.3 KB
RingBuffer.kt
4 KB
#Kotlin 『用四种方法写 RingBuffer……』
DiffAlgorithm.kt
5.6 KB
最终版本的 diff 算法,到底是没有什么…… 都是实现细节
Forwarded from dnaugsuz
就是 diff 算法啦,规定输出是一个序列

sealed class Change<out T>
data class Same(part: List<T>)
data class Inserted(added: List<T>)
data class Deleted(removed: List<T>)

像是这样,[] 里面的东西代表 Inserted, () 里面的东西代表 Deleted,主语是第一个输入序列
diff 操作符不考虑其对称性等性质,只作为子程序看待

举例:

diff("abc", "aebc").toString() // a [e] bc
diff("abc", "ac").toString() // a (b) c
diff("abc", "aec").toString() // a (b) [e] c
diff("abcd", "a0c1").toString() // a (b) [0] c (d) [1]

这样。
Forwarded from dnaugsuz
This media is not supported in your browser
VIEW IN TELEGRAM
Forwarded from dnaugsuz
>>> Diff.diff("Hello beautiful world".split(' '), "Goodbye cruel world".split(' '))
(Hello,beautiful) [Goodbye,cruel] world
>>> Diff.diff("Good morning".split(' '), "Good bye".split(' '))
Good (morning) [bye]
>>> Diff.diff("a b c".split(' '), "a b c".split(' '))
a,b,c
>>> Diff.diff("a b c".split(' '), "a c".split(' '))
a (b) c
>>> Diff.diff("a b c".split(' '), "a e b c".split(' '))
a [e] b,c
>>> Diff.diff("a b c".split(' '), "a e c".split(' '))
a (b) [e] c
>>> Diff.diff("a b c d".split(' '), "a 0 c 1".split(' '))
a (b) [0] c (d) [1]