View CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.21) | |
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES) | |
set(CMAKE_CUDA_ARCHITECTURES "75") | |
endif() | |
set(CMAKE_CUDA_COMPILER "/usr/local/cuda/bin/nvcc") | |
project(example-app) |
View machine.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Machine | |
enum State | |
Before | |
Run | |
After | |
Next | |
end | |
def initialize(@state : State, @line : Int32) | |
end |
View rotate.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def new_rotate!(n = 1) | |
return self if empty? | |
sz = @size | |
n %= sz | |
return self if n == 0 | |
st = to_unsafe | |
ed = st + sz | |
while (sz > 1 && n != 0) |
View benchmark.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark" | |
class Array | |
def new_rotate!(n = 1) | |
return self if empty? | |
sz = self.size | |
n %= sz | |
return self if n == 0 | |
tmp = Slice.new(to_unsafe, sz) |
View LL(1)-pg.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
annotation ParserAttr | |
end | |
annotation TopSymbolAttr | |
end | |
annotation SymbolAttr | |
end | |
annotation Rule |
View solution-1.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# channel.cr | |
class Channel(T) | |
struct Sender(T) | |
@link : Crystal::StaticList | |
end | |
Crystal::StaticList.container_of(ptr, Channel::Sender(T), @link) | |
end | |
# crystal/static_list.cr |
View bench.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ch = Channel(Int32).new | |
done = Channel(Time::Span).new | |
count = (ARGV[0]? || 1000).to_i | |
4.times do | |
spawn do | |
delay = Time::Span::ZERO | |
count.times do |i| |
View bench.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
total_delay = Time::Span::ZERO | |
done = Channel(Time::Span).new | |
(ARGV[0]? || 1000).to_i.times do |i| | |
ch = Channel(Int32).new | |
501.times do |j| | |
if j == 250 | |
spawn do | |
delay = Time.measure do |
View bench.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ch1 = Channel(Int32).new | |
ch2 = Channel(Int32).new | |
500.times do | |
spawn do | |
r = Random.new | |
ch2.send(r.next_int) | |
end | |
end |
View static_list.cr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro container_of(ptr, _type, member) | |
{% if _type.resolve < Reference %} | |
(({{ ptr }}).as(Void*) - offsetof({{ _type }}, {{ member }})).as({{ _type }}) | |
{% else %} | |
(({{ ptr }}).as(Void*) - offsetof({{ _type }}, {{ member }})).as(Pointer({{ _type }})) | |
{% end %} | |
end | |
struct StaticList | |
@prev = uninitialized Pointer(StaticList) |
NewerOlder