#Java #code
import java.util.function.Function;
import java.lang.reflect.*; //Proxy, InvocationHandler, Method
class Sam {
<FUNC, T, R> FUNC functor(Class<FUNC> fn_type, Function<T, R> impl) {
FUNC fn = (FUNC)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{fn_type}, new InvocationHandler() {
@Override public Object invoke(Object o, Method m, Object[] args) { return impl.apply((T)args[0]); } // self(o) ignored, argc&m unchecked
}); //< or use Proxy.getInvocationHandler(impl) to re-dispatch(require samename)
return fn;
}
interface XXCall { int call(int x); }
static public void main(String... a) {
Function<Integer,Integer> f = (x) -> x+1;
System.out.println(new Sam().functor(XXCall.class, f).call(1));
}
}
#essay #Java 想了下最近的操作
我是想给 JPlayer1 加上 buffer size 参数,再允许负 size 的 multi-thead Queue 渲染,不必手动 RingBuffer
再写一个最简版的 JPlayer3 ,反映无 queue 的绘制逻辑(草生)
想到 ANSI 命令台控制,又想拿 Java 配合下 JNI 去写贪吃蛇,死性不改…… 连怎么取 winsize(w,h) 都想了,JNI 返回 int[] 麻烦,就接收 int[] ,或者干脆变成 long(bitsize=2*int) 甚至 double,没问题的 ;只需要提供
(吐嘈:写完坏苹果以后我还会做 buffering 了……什么鬼)
现在我终于明白了命令台 REPL 的 Tab 补全是可以 10 行代码以内实现的,看来杂学对 ParserKt 也有用啊,下次就有经验了,复杂的初始化逻辑都倒大霉。
搞完这些又要把之前 耿爽模拟器、傅立叶变换动画 重构了
之前我还以为耿爽模拟器多难写,主要就是想
刚开始不习惯编程 记忆变量关系,老是把 N append iter : 1 [noun,verb] cfg 这种简单逻辑背岔,现在不会了(老智障了 草)
主要是当初想“既然能拼接,能不能再写个函数「学习」这些文本数据”,后来才发现其实一个 String.replace 就能搞定,也就是说这个函数没比 replace 高到哪去,还是要 text 以外的参数,不过现在我觉得是可以统计下词频的,但那就要 NLP 了,目前我会用 Py 的
傅立叶的那个是真大佬,不知道是否驾驭的住,反正我对 js canvas 是绝对不熟练的
搞完了还有 mohu 的控制台 game 要重构,得把 List<
C++ 11 的 coding convert 还真是不习惯,看起来 wcout 在 Wine 没有用,只能是 wstring_convert API 了
想着这个按换行、分号切分的 2维文本数组 可不可以用
还是要走 C 的 malloc +full read 那种吗,当然 bytes->Unicode int 是必须的,有时候真想念 Python 那奇怪的 encode decode 啊,写完了或许能做 WASM 支持
我是想给 JPlayer1 加上 buffer size 参数,再允许负 size 的 multi-thead Queue 渲染,不必手动 RingBuffer
再写一个最简版的 JPlayer3 ,反映无 queue 的绘制逻辑(草生)
想到 ANSI 命令台控制,又想拿 Java 配合下 JNI 去写贪吃蛇,死性不改…… 连怎么取 winsize(w,h) 都想了,JNI 返回 int[] 麻烦,就接收 int[] ,或者干脆变成 long(bitsize=2*int) 甚至 double,
initScr(); printYX(y,x,s); endScr(); 然后封装个 writeLineN(n, s) 即可刷写屏幕(最开始打算让 initScr 返回行列大小,或者搞 yxprintf, mvprintf 什么的,还好我反应块,迫真;甚至还有想利用 OOP 抽象掉这个,去兼容 Android 上刷新字符帧的……可以在手机上玩但不必重写游戏逻辑 就是不方便)(吐嘈:写完坏苹果以后我还会做 buffering 了……什么鬼)
现在我终于明白了命令台 REPL 的 Tab 补全是可以 10 行代码以内实现的,看来杂学对 ParserKt 也有用啊,下次就有经验了,复杂的初始化逻辑都倒大霉。
搞完这些又要把之前 耿爽模拟器、傅立叶变换动画 重构了
之前我还以为耿爽模拟器多难写,主要就是想
(1..randInt(10,25)).map { quotes.pick().fmt(noun=cfg[0], verb=cfg[1]) }.joinToString("") ,后来发现是主语选错了, quotes.take(randint(10,25)).shuffle { it.fmt(cfg[0],cfg[1]) }.joinToString("") 多简单(提性能可以拒绝临时 shuffled List<String> 创建 改 indices + joinToString transform)刚开始不习惯编程 记忆变量关系,老是把 N append iter : 1 [noun,verb] cfg 这种简单逻辑背岔,现在不会了(老智障了 草)
主要是当初想“既然能拼接,能不能再写个函数「学习」这些文本数据”,后来才发现其实一个 String.replace 就能搞定,也就是说这个函数没比 replace 高到哪去,还是要 text 以外的参数,不过现在我觉得是可以统计下词频的,但那就要 NLP 了,目前我会用 Py 的
jieba.cut 分词傅立叶的那个是真大佬,不知道是否驾驭的住,反正我对 js canvas 是绝对不熟练的
搞完了还有 mohu 的控制台 game 要重构,得把 List<
Pair<String,String> 和 List<String>> 的文本切分搞出来(前者是选项目对对联的游戏数据,后者是excited的界面翻译随机pick)C++ 11 的 coding convert 还真是不习惯,看起来 wcout 在 Wine 没有用,只能是 wstring_convert API 了
想着这个按换行、分号切分的 2维文本数组 可不可以用
ifstream 去读取,答案当然是不可以,如果不以 '\n', ' ' 切分就读不了啦(而且很可能不支持 unicode )还是要走 C 的 malloc +full read 那种吗,当然 bytes->Unicode int 是必须的,有时候真想念 Python 那奇怪的 encode decode 啊,写完了或许能做 WASM 支持
https://t.iss.one/c/1119363280/104914
https://t.iss.one/c/1119363280/104956
https://t.iss.one/c/1119363280/104983 #root
https://t.iss.one/c/1119363280/105043
https://t.iss.one/c/1119363280/105150 #robotic
https://t.iss.one/c/1119363280/105201 #app
https://t.iss.one/c/1119363280/105247 #aop
https://t.iss.one/c/1119363280/105266 #charset #config Context
https://t.iss.one/c/1119363280/105365 #net
https://t.iss.one/c/1119363280/105417 #events #gui
https://t.iss.one/c/1119363280/105453 #textarea
https://t.iss.one/c/1119363280/105493 #css #web
https://t.iss.one/c/1119363280/105566 #india #app
https://t.iss.one/c/1119363280/105610 #gui #xml
https://t.iss.one/c/1119363280/105612 #meme #cplusplus
https://t.iss.one/c/1119363280/105631 #electron #app
https://t.iss.one/c/1119363280/105662 #app #launcher
https://t.iss.one/c/1119363280/105715 #aosp #web #tools
https://t.iss.one/c/1119363280/105771 #packaging #presistence
https://t.iss.one/c/1119363280/106073 #java
https://t.iss.one/c/1119363280/106178 #kbdpolitics
https://t.iss.one/c/1119363280/106331 #linux
https://t.iss.one/c/1119363280/106398 api
https://t.iss.one/c/1119363280/106472 #wechat
https://t.iss.one/c/1119363280/104956
https://t.iss.one/c/1119363280/104983 #root
https://t.iss.one/c/1119363280/105043
https://t.iss.one/c/1119363280/105150 #robotic
https://t.iss.one/c/1119363280/105201 #app
https://t.iss.one/c/1119363280/105247 #aop
https://t.iss.one/c/1119363280/105266 #charset #config Context
https://t.iss.one/c/1119363280/105365 #net
https://t.iss.one/c/1119363280/105417 #events #gui
https://t.iss.one/c/1119363280/105453 #textarea
https://t.iss.one/c/1119363280/105493 #css #web
https://t.iss.one/c/1119363280/105566 #india #app
https://t.iss.one/c/1119363280/105610 #gui #xml
https://t.iss.one/c/1119363280/105612 #meme #cplusplus
https://t.iss.one/c/1119363280/105631 #electron #app
https://t.iss.one/c/1119363280/105662 #app #launcher
https://t.iss.one/c/1119363280/105715 #aosp #web #tools
https://t.iss.one/c/1119363280/105771 #packaging #presistence
https://t.iss.one/c/1119363280/106073 #java
https://t.iss.one/c/1119363280/106178 #kbdpolitics
https://t.iss.one/c/1119363280/106331 #linux
https://t.iss.one/c/1119363280/106398 api
https://t.iss.one/c/1119363280/106472 #wechat
https://t.iss.one/c/1119363280/109316 #reveng ndk onCreate
https://t.iss.one/c/1119363280/109356 #huawei homoOs( #旧事重提
https://t.iss.one/c/1119363280/109367 xposed #wechat
https://t.iss.one/c/1119363280/109378 #china #robotic #旧事重提 光年实验室
https://t.iss.one/c/1119363280/109402 #framework
https://t.iss.one/c/1119363280/109498 #i18n #china #haha 祖安汉化
https://t.iss.one/c/1119363280/109540 #app #coolapk #wechat
https://t.iss.one/c/1119363280/109578 #web https://ai DNS 有意思
https://t.iss.one/c/1119363280/109703 #huawei #旧事重提 HomoDroid 笑死
https://t.iss.one/c/1119363280/109845 #android #sysadmin
https://t.iss.one/c/1119363280/109918 #telegram #acg #tools @WhatAnimeBot
https://t.iss.one/c/1119363280/109946 草 #cplusplus #build #packaging
https://t.iss.one/c/1119363280/109958 #app #security 老kit 了
https://t.iss.one/c/1119363280/110001 Gitee routing OAuth? #security #http
https://t.iss.one/c/1119363280/110210 #android 模拟器 SafetyNet. 甚至私聊攻击 Rikka 生气了 #sb https://t.iss.one/c/1119363280/110347
https://t.iss.one/c/1119363280/110452 PackageManager
https://t.iss.one/c/1119363280/110473 #recommended #android #backend #gui #blog gityuan.com
https://t.iss.one/c/1119363280/110634 #huawei #google #low
https://t.iss.one/c/1119363280/110662 #plt #typing #java
https://t.iss.one/c/1119363280/110677 #json #algorithm LinkedHashMap
https://t.iss.one/c/1119363280/110743 #qt
https://t.iss.one/c/1119363280/109356 #huawei homoOs( #旧事重提
https://t.iss.one/c/1119363280/109367 xposed #wechat
https://t.iss.one/c/1119363280/109378 #china #robotic #旧事重提 光年实验室
https://t.iss.one/c/1119363280/109402 #framework
https://t.iss.one/c/1119363280/109498 #i18n #china #haha 祖安汉化
https://t.iss.one/c/1119363280/109540 #app #coolapk #wechat
https://t.iss.one/c/1119363280/109578 #web https://ai DNS 有意思
https://t.iss.one/c/1119363280/109703 #huawei #旧事重提 HomoDroid 笑死
https://t.iss.one/c/1119363280/109845 #android #sysadmin
https://t.iss.one/c/1119363280/109918 #telegram #acg #tools @WhatAnimeBot
https://t.iss.one/c/1119363280/109946 草 #cplusplus #build #packaging
https://t.iss.one/c/1119363280/109958 #app #security 老kit 了
https://t.iss.one/c/1119363280/110001 Gitee routing OAuth? #security #http
https://t.iss.one/c/1119363280/110210 #android 模拟器 SafetyNet. 甚至私聊攻击 Rikka 生气了 #sb https://t.iss.one/c/1119363280/110347
https://t.iss.one/c/1119363280/110452 PackageManager
https://t.iss.one/c/1119363280/110473 #recommended #android #backend #gui #blog gityuan.com
https://t.iss.one/c/1119363280/110634 #huawei #google #low
https://t.iss.one/c/1119363280/110662 #plt #typing #java
https://t.iss.one/c/1119363280/110677 #json #algorithm LinkedHashMap
https://t.iss.one/c/1119363280/110743 #qt
duangsues.is_a? SaltedFish
https://t.iss.one/c/1119363280/109316 #reveng ndk onCreate https://t.iss.one/c/1119363280/109356 #huawei homoOs( #旧事重提 https://t.iss.one/c/1119363280/109367 xposed #wechat https://t.iss.one/c/1119363280/109378 #china #robotic #旧事重提 光年实验室 https://t.iss.one/c/1119363280/109402 #framework…
https://github.com/SimpleMobileTools/Simple-SMS-Messenger #app sms
https://t.iss.one/c/1119363280/110892 #tech #windows
https://t.iss.one/c/1119363280/111015 #cplusplus #Linux #code
https://t.iss.one/c/1119363280/111049 #linux #sysadmin
https://t.iss.one/c/1119363280/111064 #GUI jetpack compose
https://t.iss.one/c/1119363280/111371 #Android #news cnBeta
https://t.iss.one/c/1119363280/111393 #cplusplus #bug 低级错误
https://t.iss.one/c/1119363280/111426 #parsing #Linux cmdline #Python shlex
https://t.iss.one/c/1119363280/111569 #root 读取 sms
https://t.iss.one/c/1119363280/111642 #Google #packaging #low
https://t.iss.one/c/1119363280/111683 #statement 草真理了,每次你不想做什么事情,或者就想写个小工具,那东西偏偏会变好……
https://t.iss.one/c/1119363280/111899 #Java #code #dev #Haha
https://t.iss.one/c/1119363280/112061 同上
https://t.iss.one/c/1119363280/112142 #naked #hardware Verilog 草
https://t.iss.one/c/1119363280/112323 #Android #ali #GitHub 草草
https://t.iss.one/c/1119363280/112460 #Apple #security OCSP
https://t.iss.one/c/1119363280/112695 #Android #dev
https://t.iss.one/c/1119363280/112729 #lib 直接调试用 ui
https://t.iss.one/c/1119363280/112873 #Haha #Android #Google #school #Security 😂
https://t.iss.one/c/1119363280/113043 #Android #build
https://t.iss.one/c/1119363280/113104 #Java primData
https://t.iss.one/c/1119363280/113573 #Kotlin #code #security
https://t.iss.one/c/1119363280/110892 #tech #windows
https://t.iss.one/c/1119363280/111015 #cplusplus #Linux #code
https://t.iss.one/c/1119363280/111049 #linux #sysadmin
https://t.iss.one/c/1119363280/111064 #GUI jetpack compose
https://t.iss.one/c/1119363280/111371 #Android #news cnBeta
https://t.iss.one/c/1119363280/111393 #cplusplus #bug 低级错误
https://t.iss.one/c/1119363280/111426 #parsing #Linux cmdline #Python shlex
https://t.iss.one/c/1119363280/111569 #root 读取 sms
https://t.iss.one/c/1119363280/111642 #Google #packaging #low
https://t.iss.one/c/1119363280/111683 #statement 草真理了,每次你不想做什么事情,或者就想写个小工具,那东西偏偏会变好……
https://t.iss.one/c/1119363280/111899 #Java #code #dev #Haha
https://t.iss.one/c/1119363280/112061 同上
https://t.iss.one/c/1119363280/112142 #naked #hardware Verilog 草
https://t.iss.one/c/1119363280/112323 #Android #ali #GitHub 草草
https://t.iss.one/c/1119363280/112460 #Apple #security OCSP
https://t.iss.one/c/1119363280/112695 #Android #dev
https://t.iss.one/c/1119363280/112729 #lib 直接调试用 ui
https://t.iss.one/c/1119363280/112873 #Haha #Android #Google #school #Security 😂
https://t.iss.one/c/1119363280/113043 #Android #build
https://t.iss.one/c/1119363280/113104 #Java primData
https://t.iss.one/c/1119363280/113573 #Kotlin #code #security
GitHub
GitHub - SimpleMobileTools/Simple-SMS-Messenger: An easy and quick way of managing SMS and MMS messages without ads.
An easy and quick way of managing SMS and MMS messages without ads. - SimpleMobileTools/Simple-SMS-Messenger
https://t.iss.one/c/1119363280/113691 #security #linux #meme #Python socket.recvuntil() 之前没用过
https://t.iss.one/c/1119363280/113807 #csharp
https://t.iss.one/c/1119363280/113932 #file Android IDE
https://t.iss.one/c/1119363280/114030 #Android #build
https://t.iss.one/c/1119363280/114073 #Kotlin synthesis 变 #GUI viewbinding..
https://t.iss.one/c/1119363280/114199 #Java #android
https://t.iss.one/c/1119363280/114288 #China #hk .
https://t.iss.one/c/1119363280/114460 #Android 通话录音
https://t.iss.one/c/1119363280/114591 #linux #sysadmin
https://t.iss.one/c/1119363280/114646 #GitHub #China #security
https://t.iss.one/c/1119363280/113807 #csharp
https://t.iss.one/c/1119363280/113932 #file Android IDE
https://t.iss.one/c/1119363280/114030 #Android #build
https://t.iss.one/c/1119363280/114073 #Kotlin synthesis 变 #GUI viewbinding..
https://t.iss.one/c/1119363280/114199 #Java #android
https://t.iss.one/c/1119363280/114288 #China #hk .
https://t.iss.one/c/1119363280/114460 #Android 通话录音
https://t.iss.one/c/1119363280/114591 #linux #sysadmin
https://t.iss.one/c/1119363280/114646 #GitHub #China #security
duangsues.is_a? SaltedFish
绿色的都比黄色小 红色都比黄色大 只要判断 黄色和你的数据的关系 就能排除掉 上面或者下面那一块
duangsuse:
二分查找还是分治嘛,对了它是几个指针来着 真的能斜切线吗
大 佬: #algorithm #Java #code
二分查找还是分治嘛,对了它是几个指针来着 真的能斜切线吗
大 佬: #algorithm #Java #code
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int lenSize = matrix.length;
int rowSize = matrix[0].length;
return search(matrix, 0, lenSize, 0, rowSize, target);
}
private boolean search(int[][] matrix, int a1, int b1, int a2, int b2, int target){
if(a1 == b1 || a2 == b2){
return false;
} else {
int mid1 = (a1 + b1) / 2;
int mid2 = (a2 + b2) / 2;
if(matrix[mid1][mid2] == target){
return true;
} else if(target > matrix[mid1][mid2]){
return search(matrix, a1, mid1 + 1, mid2 + 1, b2, target) || search(matrix, mid1 + 1, b1, a2, b2, target);
} else {
return search(matrix, mid1, b1, a2, mid2, target) || search(matrix, a1, mid1, a2, b2, target);
}
}
}
}
Deleted Account
以下是使用反射进行深拷贝的示例代码,支持将 `List`、`HashMap` 和对象的字段(使用 `getFields()` 方法获取)映射为新的值,并可以使用 `unifyEqualsPtrs()` 函数将相同的对象指针映射为相同的新对象: ```java import java.lang.reflect.*; import java.util.*; public class DeepCopyUtil { private static Map<Object, Object> originalToCopy…
在kotlin 用java reflect 写一个深度遍历对象图的 deepSetAs(obj,func) ,它支持将 List.E,Map.V,getFields() 内的值修改为func调用
以此定义 unifyEqualsPtrs(obj, oldToDup=mutMap())=deepSet{ computeIfAbsent }
请用函数式,when 减少缩进
它没有返回值,只原地改写 。然后field也要递归 ,而且不要处理str,enum 等基础类型
柯里化 deepSetAs(func)(it) ,递归改成 see(it)。 unify也要
deepSetAs不要有T, obj作为this, else->外提为 forListyFields(see); unify可以是val 。缩进2空格
ref:https://t.iss.one/dsuse/18706
也可以加个fn参数,调用0参构造器 作为返回,实现deepCopy
好的,我根据你的要求再次修改了一下代码,你看看这样可以吗:
#kt #code
解答了 https://t.iss.one/Javaer/922625
以此定义 unifyEqualsPtrs(obj, oldToDup=mutMap())=deepSet{ computeIfAbsent }
请用函数式,when 减少缩进
它没有返回值,只原地改写 。然后field也要递归 ,而且不要处理str,enum 等基础类型
柯里化 deepSetAs(func)(it) ,递归改成 see(it)。 unify也要
deepSetAs不要有T, obj作为this, else->外提为 forListyFields(see); unify可以是val 。缩进2空格
ref:https://t.iss.one/dsuse/18706
也可以加个fn参数,调用0参构造器 作为返回,实现deepCopy
好的,我根据你的要求再次修改了一下代码,你看看这样可以吗:
#kt #code
kotlin
fun deepSetAs(func: (Any?) -> Any?): Any?.()->Unit = { ->
val see = deepSetAs(func)
when (this) {
is List<*> -> forEach { see(it) }
is Map<*, *> -> forEach { see(it.value) }
else -> this?.forListyFields(see)
}
}
val cf = mutableMapOf<Class<*>, Array<Field>>()
fun Any.forListyFields(see: (Any?) -> Unit) { cf.getOrPut(this.javaClass) { this.javaClass.declaredFields }.forEach {
it.isAccessible = true
val v = it.get(this)
if (v != null && v !is String && v !is Enum<*>) {
see(v)
}
it.set(this, func(v))
}
}
val unifyEqualsPtrs = { val dup2Old=mutableMapOf<Any?, Any?>()
deepSetAs { v -> dup2Old.computeIfAbsent(v) { v } }
} 解答了 https://t.iss.one/Javaer/922625
Telegram
duangsuse::Echo
#java #performance 值类型vs引用类型
🤔在内存管理/GC良好的语言里,只读数据的引用 就是值
java Byte[]和byte[] 在复用上都互不兼容,当然没有值类型了☺️
>我有一个含极多重复str 的JSON,想减少其内存占用
这就是常量池嘛, javac和aapt都会做
JVM的str不可变,一般都是全局缓存的,strBuild 在完成时是会查询这个吧。
文件上编解码时中间加个Deflate流
也可能是结构有毛病, 比如把str而非int当成tag
说起来str.intern…
🤔在内存管理/GC良好的语言里,只读数据的引用 就是值
java Byte[]和byte[] 在复用上都互不兼容,当然没有值类型了☺️
>我有一个含极多重复str 的JSON,想减少其内存占用
这就是常量池嘛, javac和aapt都会做
JVM的str不可变,一般都是全局缓存的,strBuild 在完成时是会查询这个吧。
文件上编解码时中间加个Deflate流
也可能是结构有毛病, 比如把str而非int当成tag
说起来str.intern…