2013-07-01から1ヶ月間の記事一覧

rubyで行の置き換え

rubyでkeyの行の置き換え f=open("test1.txt"); a=Hash.new(); f.readlines.each{|i| i.chomp!; j=i.split(" ") a[j[0]+" "+j[1]]=i; # puts i; } f2=open("test2.txt"); f2.readlines.each{|i| i.chomp! j=i.split(" ") if a.has_key?(j[0]+" "+j[1]) then …

scalaで配列のランダムシャッフル c++の関数の利用

JNAを使ってc++のシャッフル関数と連携. c_shuff_test.scala import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLibrary; object c_shuff_test{ def main(args: Array[String]): Unit={ val lib=NativeLibrary.getInstance…

scalaからc++関数を使う

scalaからjnaでc++関数を使う。 少しはまった.ポイントは関数にextern "C" をつけること. C++では、関数のオーバーロード(多重定義)などが原因で 関数名で関数が特定できない(識別子がつくらしい)。そこで、C方式の関数名として宣言しておく. http://…

scalaとC言語で配列の値の1をたす,ポインタ渡しの例

cpp_test.scala import com.sun.jna.Library; import com.sun.jna.Native; import com.sun.jna.NativeLibrary; object cpp_test{ def main(args: Array[String]): Unit={ var a=Array(1.0,2.0,3.0); println("Input"); a.foreach{println} val lib=NativeLib…

scalaとcで内積

scalaからcの関数をよび内積を計算loop.c #include<stdio.h> #include<stdlib.h> #include<math.h> #include"loop.h" int loop2(double* v1, double* v2,int n){ double tmp=0; int i; for(i=0;i</math.h></stdlib.h></stdio.h>

cのヘッダーファイルの意味

c

はじめてC言語 .hファイルの意味を理解した! cのヘッダーファイルの意味 http://www.geocities.jp/ky_webid/ProgrammingPlacePlus/c/023.html ポイントは, 各ファイルで関数宣言をしないと関数を使用できない →これが.hファイル実態は,.cファイルで定義す…

wgetでhttpsで証明書が信用できずにダウンロードできない

まず、普通にダウンロードすると wget https://maven.java.net/content/repositories/releases/net/java/dev/jna/jna/3.5.2/jna-3.5.2.jar エラー: `maven.java.net' の証明書は信用されません。 エラー: `maven.java.net' の証明書の発行者が不明です。とな…

scalaからCのプログラムを読みだす

(1)まず準備。 C言語のダイナミックリンクライブラリ(dll)を作る #include<stdio.h> void test_hello(char* v){ printf(v); } dll化する gcc -c test_hello.c gcc -shared -o test_hello.dll test_hello.o 実行用プログラム void main(){ test_hello("This is test</stdio.h>…