Skip to content

Instantly share code, notes, and snippets.

View kubo39's full-sized avatar
💭
I may be slow to respond.

Hiroki Noda kubo39

💭
I may be slow to respond.
View GitHub Profile
@kubo39
kubo39 / compile_time_fizzbuzz.d
Created February 21, 2023 00:53
compile-time fizzbuzz
string f(alias T, Args...)()
{
string s;
static if (T % 3 == 0) s ~= "fizz";
static if (T % 5 == 0) s ~= "buzz";
static if (T % 3 != 0 && T % 5 != 0) s ~= T.stringof;
static if (Args.length > 0) return s ~ "," ~ f!(Args)();
else return s;
}
pragma(msg, f!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15));
import std;
static assert(isInstanceOf!(Array, Array!char));
static assert(!isInstanceOf!(Regex, Regex!char));
static assert(isInstanceOf!(TemplateOf!(Regex!char), Regex!char));
static assert(__traits(isSame, TemplateOf!(Array!char), Array));
static assert(!__traits(isSame, TemplateOf!(Regex!char), Regex));
static if (is(Array!char == T1!Args1, alias T1, Args1...))
import std.stdio;
void main()
{
// 型情報の取得: : https://dlang.org/spec/type.html#typeof
alias rt = typeof(1.0);
// 型名: https://dlang.org/spec/property.html#stringof
writeln(rt.stringof); // double

D言語のfloat-parsing algorithm ("somestr".parse!double) について

Phobosのfloat parsing algorithmをみていく。

単純化したもので考える。

nanとかinfとかはみればわかるので(単に文字比較しているだけ)そこは飛ばす。

それでも結構長いな。

@kubo39
kubo39 / ice1.go
Last active September 18, 2021 13:15
go generics ICE
package main
import "fmt"
// T interface{ uint8 } だと通る
func Foo[T interface{ int }, S interface{ *T }](x T) S {
// ここで incompatible type: cannot use &x (value of type *T) as S value となるべき?
// -> いやむしろ *T --> *uint8 になるのがおかしいのか
return &x
@kubo39
kubo39 / atomic_unko.md
Last active June 15, 2022 00:14
共有資源へのアクセスの違いについて: 頭にあるのをざっと書いてもうちょいちゃんと調べてまとめる

並列並行処理とリソース共有の安全性

Goがあらゆる点において並行処理で優れているわけではないよ、という話。

Go

  • Goは組み込みチャネルやgoroutineのような仕組みもあり実際に並列並行処理に強みがあるが落とし穴はそれなりにある
    • WaitGroupのカウントアップをgoroutine内でやるな、とか
  • ここでは共有資源へのアクセス・書き込みの安全性について考える
  • Goは共有資源への操作にかんする型レベルでの安全性にかんして欠如している
@kubo39
kubo39 / bench.log
Last active September 7, 2019 13:53
(dmd-2.088.0)$ ./bench.sh
~/dev/dlang/vibe.d ~/dev/dlang
+ git checkout master
Already on 'master'
Your branch is up to date with 'upstream/master'.
+ git rev-parse HEAD
da8d30598bdf9401d512a46a077c62b061926e18
+ set +x
~/dev/dlang/vibe.d/examples/bench-http-server ~/dev/dlang/vibe.d ~/dev/dlang
+ wrk -c 1000 -d 10s http://localhost:8080/
@kubo39
kubo39 / profile.md
Last active February 28, 2020 03:14

並行並列スタック

並行並列スタック

  • 生スレッド・ロック
  • futures-rs
  • crossbeam-channel (メッセージパッシングによる並行処理)
  • rayon (タスクベースの並列処理ライブラリ)
  • Atomic・ロックフリーデータ構造