大きなファイルをすばやくフィルタリングする


11

大きなファイルをすばやくフィルタリングすることが課題です。

  • 入力:各行には、スペースで区切られた3つの正の整数があります。
  • 出力:すべての入力行A BT満足は、以下のいずれかの基準のこと。

    1. 別の入力ラインが存在するCDUどこD = A0 <= T - U < 100
    2. 別の入力ラインが存在するCDUどこB = C0 <= U - T < 100

テストファイルを作成するには、テストにも使用される次のPythonスクリプトを使用します。1.3Gファイルを作成します。もちろん、テストのnolinesを減らすことができます。

import random    
nolines = 50000000 # 50 million
for i in xrange(nolines):
    print random.randint(0,nolines-1), random.randint(0,nolines-1), random.randint(0,nolines-1)

ルール。コンピューターで上記のスクリプトを使用して作成した入力ファイルでテストした場合の最速のコードが優先されます。締め切りは最初の正しいエントリーの時から1週間です。

私のマシンタイミングは私のマシンで実行されます。これは、AMD FX-8350 8コアプロセッサへの標準8GB RAM Ubuntuインストールです。これは、コードを実行できる必要があることも意味します。

関連するタイミング情報

各テストの前に以下を実行するようにタイミングが更新されました。

sync && sudo bash -c 'echo  3 > /proc/sys/vm/drop_caches'

time wc test.file

real    0m26.835s
user    0m18.363s
sys     0m0.495s

time sort -n largefile.file  > /dev/null

real    1m32.344s
user    2m9.530s
sys     0m6.543s

エントリーの状況

各テストの前に次の行を実行します。

sync && sudo bash -c 'echo  3 > /proc/sys/vm/drop_caches'
  • Perl(バグ修正を待機しています。)
  • @James_picによるScala 1分37秒。(scala -J-Xmx6g Filterer largefile.file output.txtを使用)
  • Java。@Geobitsによる1分23秒。(java -Xmx6g Filter_26643を使用)
  • C。@ScottLeadleyによる2分21秒。
  • C。@James_picによる28秒。
  • Python + pandas。たぶん、単純な「groupby」ソリューションがありますか?
  • C。@KeithRandallによる28秒。

受賞者はキースランドールとジェームスピックです。

私は彼らの実行時間を区別することができませんでした、そしてどちらもトイレとほとんど同じくらい速いです!


1
たぶん、[最速コード]ではないチャレンジを書いてみてください。
ジャスティン


2
正の整数を定義してください。1 < n < 2147483647
durron597

1
@ScottLeadleyいいえ、もちろんそれが入力に複数回表示されない限り(これは非常にありそうもないと思います)。

1
どのグラフィックスカードがあり、どのくらいのビデオメモリが搭載されていますか?
IchBinKeinBaum

回答:


10

C、約7 4.1秒

Tで基数ソートを行い、配列を調べて一致を探します。

キャッシュフレンドリーなので高速です。基数は適度にソートされ、最後のウォークは非常に。各行を他の約100に対してチェックする必要がありますが、それらはすべてキャッシュ内で隣接しています。

追加:他の100行のスキャンに対して各行をチェックする必要がなくなりました。ウィンドウ内のbの下位ビットのカウントの小さなテーブルは、このスキャンのほとんどのインスタンスを排除するのに十分です。

現在、約1/2回の解析、1/3回のソート、1/6回の実際のマッチングを行っています。

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>

// B = # of bits per radix pass
// R = # of radix passes
#define B 9
#define R 3
#define M ((1<<B)-1)
#define MAXN 50000000

int count[R][1<<B];

typedef struct {
  int a,b,t,print;
} entry;

entry A[MAXN];
entry C[MAXN];

// Sized to fit well in L1 cache
unsigned char bcount[16384];

int main(int argc, char *argv[]) {
  FILE *f = fopen(argv[1], "r");
  fseek(f, 0, SEEK_END);
  int size = ftell(f);
  fclose(f);

  int fd = open(argv[1], O_RDONLY);
  const char *p = (const char*)mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);
  const char *endp = p + size;

  // parse, insert into array
  int n = 0;
  while(p < endp) {

    // parse line
    int a = 0;
    while(*p != ' ') {
      a *= 10;
      a += *p - '0';
      p++;
    }
    p++;
    int b = 0;
    while(*p != ' ') {
      b *= 10;
      b += *p - '0';
      p++;
    }
    p++;
    int t = 0;
    while(*p != '\n') {
      t *= 10;
      t += *p - '0';
      p++;
    }
    p++;

    // insert it
    if(n == MAXN) {
      printf("too many elements\n");
      exit(1);
    }
    A[n].a = a;
    A[n].b = b;
    A[n].t = t;
    n++;

    // compute counts for radix sort
    count[0][t&M]++;
    count[1][(t>>B)&M]++;
    count[2][t>>2*B]++;
  }

  // accumulate count entries
  for(int r = 0; r < R; r++) {
    for(int i = 0; i < M; i++) {
      count[r][i+1]+=count[r][i];
    }
  }

  // radix sort, 3 rounds
  for(int i = n-1; i >= 0; i--) {
    C[--count[0][A[i].t&M]] = A[i];
  }
  for(int i = n-1; i >= 0; i--) {
    A[--count[1][(C[i].t>>B)&M]] = C[i];
  }
  for(int i = n-1; i >= 0; i--) {
    C[--count[2][A[i].t>>2*B]] = A[i];
  }

  // Walk through array (now sorted by T) and find matches.
  // We maintain a window of T values that might match.
  // To facilitate finding matches within that window, bcount
  // keeps track of a count of how many b's in that window
  // have the given low 14 bits.
  int j = 0;
  for(int i = 0; i < n; i++) {
    int a = C[i].a;
    int t = C[i].t;
    while(C[j].t <= t - 100) {
      int x = C[j].b & 16383;
      if(bcount[x] != 255) bcount[x]--;
      j++;
    }
    if(bcount[a & 16383] > 0) {
      // somewhere in the window is a b that matches the
      // low 14 bits of a.  Find out if there is a full match.
      for(int k = j; k < i; k++) {
        if(a == C[k].b)
          C[k].print = C[i].print = 1;
      }
    }
    int x = C[i].b & 16383;
    if(bcount[x] != 255) bcount[x]++;
  }
  for(int i = 0; i < n; i++) {
    if(C[i].print)
      printf("%d %d %d\n", C[i].a, C[i].b, C[i].t);
  }
}

これは最初に等しいです。基数ソートが、あなたがそれをひどいキャッシュパフォーマンスを持っていると通常思っているほど速いことに驚いています。同じテストファイルを使用しても、実行ごとにタイミングが正確に異なるため、それらを区別するためにシングルユーザーモードでテストする必要があると思います。

はい!大好きです。キャッシュの局所性によってTへの参加が速くなると感じていましたが、ソートの段階では利益が相殺されると常に考えていました。基数ソートを使用すると、それをほとんど排除できます。
James_pic 2014年

読み取りの1つのストリームと書き込みのNのストリーム(私のコードではN = 512)があるため、基数ソートはキャッシュでうまく機能します。キャッシュにN + 1のキャッシュラインがある限り、すべてがキャッシュに残ります。
キースランドール

いまいましい。私は文字通りfilter.c同じことをするために作成し、質問に出てこれを見つけました。+1
ジオビット、2014年

1
@Lembik:コードはB * R = 27ビットの数値のみを並べ替えます。これで29ビットの数値が得られました。パスを1つ追加(R ++)またはパスごとに1ビット追加(B ++)する必要があります。B ++の方がおそらく簡単です。Rはいくつかの展開されたループでハードコードされています。
キースランドール

7

Scala 2.10-0:41

問題は基本的に:

select * from data x, data x where x.a = y.b and 0 <= x.t - y.t and x.t - y.t < 100

ほとんどのRDBMSは、fromからx.atoへの結合y.bが最も特異性が高いことに気づき、これをハッシュ結合として計画します。

それが私たちがすることです。のデータのハッシュテーブルを作成aし、の同じテーブルにハッシュ結合bし、の違いをフィルタリングしtます。

import scala.io.Source
import scala.reflect.ClassTag
import java.io._

object Filterer {
  def roundUpToNextPowerOfTwo(x: Int) = {
    // blatantly stolen from http://bits.stephan-brumme.com/roundUpToNextPowerOfTwo.html
    var y = x - 1
    y |= y >> 1
    y |= y >> 2
    y |= y >> 4
    y |= y >> 8
    y |= y >> 16
    y + 1
  }

  // We hash join the array with itself, a to b, and emit both rows if t is within 100. 50m records should fit into 8GB OK.
  def main(args: Array[String]): Unit = {
    val input = Source.fromFile(args(0), "ASCII").getLines()
    val output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(args(1)), "US-ASCII"))
    try {
      val data1: Array[Row] = input.map{line =>
        Row(line)
      }.toArray

      /*
       * In theory, data1 and data2 could be created in parallel, but OpenHashMultiMap needs
       * to know its size at creation time, to sidestep the need for rehashing. I could just
       * hard-code 50 million (the size of the data in the challenge), but that seems dishonest.
       */
      val data2 = new OpenHashMultiMap[Int, Row](roundUpToNextPowerOfTwo(data1.size) * 2, -1)
      for (r <- data1) data2.insert(r.a, r) // data2 is hashed by a

      for (row1 <- data1.par) {
        val Row(a, b, t) = row1
        for (Row(c, d, u) <- data2.get(b) if (0 <= u - t) && (u - t < 100)) {
          // The conditions are symmetric, so if row1 matches, so does row2
          output.write(s"$a $b $t\n$c $d $u\n")
        }
      }
    } finally {
      output.close()
    }
  }
}

object Row {
  def apply(data: String): Row = {
    val l = data.length
    var i = 0
    var a = 0
    var b = 0
    var c = 0
    while (data.charAt(i) != ' ') {
      a = a * 10 + (data.charAt(i) - '0')
      i += 1
    }
    i += 1
    while (data.charAt(i) != ' ') {
      b = b * 10 + (data.charAt(i) - '0')
      i += 1
    }
    i += 1
    while (i < l) {
      c = c * 10 + (data.charAt(i) - '0')
      i += 1
    }
    Row(a, b, c)
  }
}

final case class Row(a: Int, b: Int, t: Int)

/*
 * None of the standard Java or Scala collections are particularly efficient as large MultiMaps,
 * so we write our own. We use open hashing with quadratic probing.
 */
class OpenHashMultiMap[@specialized(Int) K: ClassTag, V: ClassTag](capacity: Int, default: K) {
  require((capacity & (capacity - 1)) == 0) // Power of 2 capacity
  private val keys = Array.fill(capacity)(default)
  private val values = new Array[V](capacity)
  private val mask = capacity - 1

  private def hash(k: K) = {
    // Hash mingling - Int has a particularly poor hash
    k.hashCode * 428916315
  }

  def insert(k: K, v: V) = {
    var found = false
    var loc = hash(k) & mask
    var inc = 0
    while (inc <= capacity && !found) {
      loc = (loc + inc) & mask
      inc += 1
      found = keys(loc) == default
    }
    keys(loc) = k
    values(loc) = v
  }

  def get(key: K) = new Traversable[V] {
    override def foreach[U](f: V => U) = {
      var break = false
      var loc = hash(key) & mask
      var inc = 0
      while (inc <= capacity && !break) {
        loc = (loc + inc) & mask
        inc += 1
        val k = keys(loc)
        if (key == k) f(values(loc))
        else if (k == default) break = true
      }
    }
  }
}

コンパイル:

scalac Filterer.scala

そして実行します:

scala -J-server -J-XX:+AggressiveOpts -J-Xms6g -J-Xmx6g Filterer input_file.dat output_file.txt

私のマシンでは、これは2分27で実行されます。

それでも、@ Lembikの回答からアプローチを試すことは興味深いかもしれませんが、より高速な言語で行います。これはのマージ結合のようなものに対応しますt。紙の上では遅くなるはずですが、キャッシュの局所性が向上するため、先に進む可能性があります。

更新

私は、驚くほど小さな変更-優れたハッシュシングラー-でかなりの時間の休暇を削ることができました。ハッシュマップはハッシュクランプに非常に敏感なので、この変更により、私のマシンではハッシュマップが1:45に下がります。

その時間のほとんどは、データを配列に読み込むのに費やされます。

私のデータ読み取りコードが@Geobitsよりもはるかに遅い理由に興味があります。Thread.startバグが修正されると、私のコードでデータを読み取るのに70秒かかります-プログラム全体の@Geobitsよりも長くなります。データを読み取るための@Geobitsのアプローチを盗もうとしていますが、Stack Exchangeの神々がそれについてどう感じるかはわかりません。

アップデート2

今回はデータリーダーにさらに改良を加えました。ループ内でパターンマッチングとモナド演算を使用するとパフォーマンスが低下したため、簡略化しました。私scala.io.Sourceが取り組むべき次のボトルネックだと思います。

現在、私のマシンでは1:26に下がっています。

アップデート3

ガットはを取り除くprobeOpenHashMultiMapから。コードはよりjava風になり、1:15で実行されます。

アップデート4

現在、FSMを使用して入力を解析しています。実行時間が0:41に下がっている


James_pic.scala:42:error: ')'が予想されますが、文字列リテラルが見つかりました。output.write(s "$ a $ b $ t \ n $ c $ d $ u \ n")^ 1つのエラーが見つかりました。これはScalaコンパイラバージョン2.9.2にあります

1
2.10.3で動作するようになりました。6 GBのRAMの割り当てを解除しようとするため、私の貧弱なコンピューターは1分間程度使用できなくなりますが、これは非常に優れたソリューションです。

うん、ごめん。私はあなたがその問題を抱えているかもしれないと考えました。UbuntuにはまだScala 2.9が付属しており、文字列補間には2.10以上が必要です。私はそれがJava 8の下でより速くなると思いますが、Ubuntuは7でのみ出荷され、それはあなたが必要としない痛みの世界です!
James_pic 2014年

再入力:私は常にを使用するわけではありませんが、使用StringTokenizerすると何百万もの文字列を解析します。
Geobits、2014年

@Geobitsええ、String.split現在はボトルネックですが、StringTokenizer今のところそれほど良くはありません-タイトな内部ループに割り当てると、すでに負荷のかかったGCに悪影響を及ぼします。私は約束をしているように思われるFSMに取り組んでいます(完全なやり過ぎである間)
James_pic '09年

6

Java:1分54秒

(私のi7で)

すべてのマッチはt相手の100以内になるため、入力をバケット化することにしましたt。100個ごとにバケットがあるため、数をチェックするには、+ /-1バケットに対してチェックするだけで済みます。

平均して、各バケットには10​​0エントリしか含まれないため、数個のバケットをスキャンするのに時間がかかりません。読み取りとバケット処理に費やされる時間の半分以上は、マッチングにかかる​​時間はわずか40秒程度です。

注: JVM設定によっては、ヒープサイズを増やす必要がある場合があります。これは、ファイル名がであることも想定していますtest.file。そうでない場合は、単に24行目で変更してください。

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Filter_26643 {

    final static int numThreads = 8; 
    final static int numInputs = 50000000;
    final static int bucketSize = 100;
    final static int numBuckets = numInputs/bucketSize;
    ArrayList<ArrayList<int[]>> buckets;

    public static void main(String[] args) {
        new Filter_26643().run();
    }

    void run(){
        try{
            buckets = new ArrayList<ArrayList<int[]>>(numBuckets);
            for(int i=0;i<numBuckets;i++)
                buckets.add(new ArrayList<int[]>(bucketSize*2));

            BufferedReader reader = new BufferedReader(new FileReader("test.file"));
            int c=0,e[];
            while(c++<numInputs){
                StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
                e = new int[] {
                                Integer.parseInt(tokenizer.nextToken()),
                                Integer.parseInt(tokenizer.nextToken()),
                                Integer.parseInt(tokenizer.nextToken())
                                }; 
                buckets.get(e[2]/100).add(e);
            }
            reader.close();

            MatchThread[] threads = new MatchThread[numThreads];
            for(int i=0;i<numThreads;i++){
                threads[i] = new MatchThread(i);
                threads[i].start();
            }
            for(int i=0;i<numThreads;i++)
                threads[i].join();

        } catch(Exception e){
            e.printStackTrace();
        }
    }

    class MatchThread extends Thread{
        int index;

        public MatchThread(int index){
            this.index = index;
        }

        @Override
        public void run() {
            for(int i=index;i<numBuckets;i+=numThreads){
                int max = i+2 >= numBuckets ? numBuckets : i+2;
                int min = i-1 < 0 ? i : i-1;
                for(int[] entry : buckets.get(i)){
                    outer:
                    for(int j=min;j<max;j++){
                        ArrayList<int[]> bucket = buckets.get(j);
                        for(int[] other : bucket){
                            if(((entry[0]==other[1] && entry[2]-other[2]<100 && entry[2]>=other[2]) || 
                                (entry[1]==other[0] && other[2]-entry[2]<100 && other[2]>=entry[2]))
                                && entry != other){
                                 System.out.println(entry[0] + " " + entry[1] + " " + entry[2]);
                                 break outer;
                            }
                        }                           

                    }   
                }
            }
        }
    }
}

5分半後、スレッド「メイン」のjava.lang.OutOfMemoryErrorで例外が発生します。GCオーバーヘッドの制限を超えました。ヒープサイズをどれだけ増やす必要がありますか?

正規のスレッドミスを犯しました!40行目Thread::runではThread.start、ではなくを使用したため、すべてmainスレッドで実行されています。を使用するとThread::start、私のマシンではランタイムが1:38から0:46に低下します。
James_pic 2014年

@James_picヒープサイズを増やしましたか?また、コンピュータ上のsort -n test.fileの時間と0:46はどのように比較されますか(RAMにないように調整できる場合)?

今使っているマシンはWindowsボックスなのでsort時間を測れません。私の場合と同じように、ヒープを最大6Gまでバンプしました(8Gがあると言ったので、それは賢明な推測のようでした)。
James_pic 2014年

1
ちなみに@Geobits、私はこのアルゴリズムが好きです。ソートのオーバーヘッドなしで、マージ結合のほとんどの利点を得ることができます。これは、ピジョンホールでソートされたマージ結合のようなものです。
James_pic 2014年

6

C-12秒

Scalaの回答をCに移植して、どれだけ多くのパフォーマンスが得られるかを確認することにしました。

a初期の配列を構築するステップをスキップし、ハッシュテーブルから直接反復することを除いて、ほぼ同じアプローチです(でオープンハッシュテーブルを構築します)(何らかの理由で、このアプローチをScalaで実行することができませんでした) -JVMのインライン化が原因だったと思います)。

可搬性を保つのは面倒なので、スレッドを気にしませんでした。

コードは次のとおりです。

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

// Should be 37% occupied with 50m entries
#define TABLE_SIZE 0x8000000
#define MASK (TABLE_SIZE - 1)
#define BUFFER_SIZE 16384
#define END_OF_FILE (-1)
#define DEFAULT_VALUE (-1)

typedef struct Row {
  int32_t a;
  int32_t b;
  int32_t t;
} Row;

int32_t hash(int32_t a) {
  return a * 428916315;
}

void insert(Row * table, Row row) {
  long loc = hash(row.a) & MASK; // Entries are hashed on a
  long inc = 0;
  while (inc <= TABLE_SIZE) {
    loc = (loc + inc) & MASK;
    inc++;
    if (table[loc].a == DEFAULT_VALUE) {
      table[loc] = row;
      break;
    }
  }
}

int readChar(FILE * input, char * buffer, int * pos, int * limit) {
  if (*limit < *pos) {
    return buffer[(*limit)++];
  } else {
    *limit = 0;
    *pos = fread(buffer, sizeof(char), BUFFER_SIZE, input);
    if (*limit < *pos) {
      return buffer[(*limit)++];
    } else return END_OF_FILE;
  }
}

void readAll(char * fileName, Row * table) {
  char* buffer = (char*) malloc(sizeof(char) * BUFFER_SIZE);
  int limit = 0;
  int pos = 0;

  FILE * input = fopen(fileName, "rb");

  int lastRead;
  Row currentRow;
  uint32_t * currentElement = &(currentRow.a);

  // As with the Scala version, we read rows with an FSM. We can
  // roll up some of the code using the `currentElement` pointer
  while (1) {
    switch(lastRead = readChar(input, buffer, &pos, &limit)) {
      case END_OF_FILE:
        fclose(input);
        return;
      case ' ':
        if (currentElement == &(currentRow.a)) currentElement = &(currentRow.b);
        else currentElement = &(currentRow.t);
        break;
      case '\n':
        insert(table, currentRow);
        currentRow.a = 0;
        currentRow.b = 0;
        currentRow.t = 0;
        currentElement = &(currentRow.a);
        break;
      default:
        *currentElement = *currentElement * 10 + (lastRead - '0');
        break;
    }
  }
  //printf("Read %d", lastRead);
}

int main() {
  Row* table = (Row*) malloc(sizeof(Row) * TABLE_SIZE);
  memset(table, 255, sizeof(Row) * TABLE_SIZE);

  readAll("test.file", table);

  // We'll iterate through our hash table inline - passing a callback
  // is trickier in C than in Scala, so we just don't bother
  for (size_t i = 0; i < TABLE_SIZE; i++) {
    Row * this = table + i;
    if (this->a != DEFAULT_VALUE) {
      // Lookup entries `that`, where `that.a == this.b`
      long loc = hash(this->b) & MASK;
      long inc = 0;
      while (inc <= TABLE_SIZE) {
        loc = (loc + inc) & MASK;
        inc++;
        Row * that = table + loc;
        if ((this->b == that->a) && (0 <= that->t - this->t) && (that->t - this->t < 100)) {
          // Conditions are symmetric, so we output both rows
          printf("%d %d %d\n", this->a, this->b, this->t);
          printf("%d %d %d\n", that->a, that->b, that->t);
        }
        else if (that->b == DEFAULT_VALUE) break;
      }
    }
  }

  free(table);
  return 0;
}

コンパイル:

gcc -std=c99 -O3 -m64 filter.c

そして実行します:

./a.out

テストファイルの場所は、「test.file」としてハードコーディングされています。

ここでも、データの読み取りにほとんどの時間がかかります(9秒未満)。マッチングには残りの時間がかかります。

繰り返しますが、これがスコット・リードリーの答えにどのように対抗するのかを見るのは興味深いでしょう。これは同じ言語を使用していますが、異なる戦略を使用しています。スコットはTに参加しています。つまり、原則として、彼は参加する必要がありますが、Tに参加すると、キャッシュの局所性が向上します。


James_pic.cを取得:関数 'readAll':James_pic.c:67:28:警告:(currentElement ==&(currentRow.a))currentElement =&の場合、個別のポインタータイプの比較にキャストがありません(デフォルトで有効) (currentRow.b);

私はあなたのスカラとCコードから非常にわずかに異なる出力を取得します。実際、1行だけが異なります。私はちょうどしましたdiff <(sort -n James_pic-c.out) <(sort -n James_pic-scala.out)

これは、指定されたa値が発生する入力に対して失敗します。nここで、n >= BUFFER_SIZE + 2
laindir

私はあなたがこのコードに<= 100とスケールコードに<100があることだけだと思います。

@レンビック私はあなたが正しいと思います。それらはひどいオフバイエラーです!
James_pic 2014年

2

perl、コアi7上の17分46秒、8 GBメモリ

まず、sort -n -k3を使用して最も重要なフィールドを順番に取得し、最新バージョンのsort(1)に組み込まれている並列処理を利用します。次に、perlは、単純なスカラーがそれぞれ80バイトのオーダー(5000万* 3 * 80は多すぎる-少なくとも12 GB)をとるという事実によって大きく妨げられるため、出力を5000万* 12バイトに丸める配列(1行あたり12バイト、各行には32ビット整数として表現できる3つの整数が含まれます)。次に、各データの(おおまかに)1/8をカバーする8つのスレッドを発射します(+いくつかのオーバーラップ)。

#!perl

use strict;
use warnings;

# find lines s.t. $lines[$M]->{a} == $lines[$N]->{b} and
#                 0 <= $lines[$M]->{t} - $lines[$N]->{t} < 100
# OR              $lines[$M]->{b} == $lines[$N]->{a} and
#                 0 <= $lines[$N]->{t} - $lines[$M]->{t} < 100

my $infile = shift;
open(my $fh, "sort -n -k3 $infile |") || die "open sort pipe: $@";

my @lines;
my $bytes_per_int = 4;
my $bytes_per_line = $bytes_per_int * 3;
my $nlines = 50_000_000;
my $buf = "\0" x ($nlines * $bytes_per_line);
my $ln = 0;
my $nprocs = 8;
my $last_group_start = 0;
my $this_group_start;
my $group = $nlines / $nprocs;
my @pids;
while(<$fh>) {
  my ($A, $B, $T) = split/\s+/;
  substr($buf, $ln * $bytes_per_line, $bytes_per_line, pack "L3", ($A, $B, $T));
  if( defined $this_group_start ) {
    if( $T - $last_group_start >= $group + 100 ) {
      if(my $pid = fork()) {
        push @pids, $pid;
        $last_group_start = $this_group_start;
        undef $this_group_start;
      } else {
#warn "checking $last_group_start - $ln...\n";
        for(my $l=$last_group_start; $l<=$ln; ++$l) {
          my $lpos = $l * $bytes_per_line;
          my ($A, $B, $T) = unpack "L3", substr($buf, $lpos, $bytes_per_line);
          my ($lA, $lB);
          my $lT = $T;
          for(my $lb=$l; $lb>=$last_group_start && $T - $lT <= 100; $lb--, $lpos -= $bytes_per_line) {
            ($lA, $lB, $lT) = unpack "L3", substr($buf, $lpos, $bytes_per_line);
            if($A == $lB || $B == $lA) {
              #print "($last_group_start) $A $B $T matches $lA $lB $lT\n";
              print "$lA $lB $lT\n$A $B $T\n";
            }
          }
        }
        exit;
      }
    }
  } elsif( !defined $this_group_start && $T - $last_group_start >= $group ) {
    $this_group_start = $ln;
  }
  $ln++;
}

waitpid $_, 0 for @pids;

ソートされていない出力:

8455767 30937130 50130
20468509 8455767 50175
47249523 17051933 111141
17051933 34508661 111215
39504040 36752393 196668
42758015 39504040 196685
25072294 28422439 329284
35458609 25072294 329375
45340163 42711710 6480186
39315845 45340163 6480248
1435779 49643646 12704996
38229692 1435779 12705039
18487099 24556657 6665821
24556657 28498505 6665884
6330540 35363455 18877328
22500774 6330540 18877347
10236123 22026399 598647
39941282 10236123 598717
45756517 24831687 6726642
34578158 45756517 6726670
29385533 7181838 621179
7181838 29036551 621189
40647929 11895227 25075557
11895227 1900895 25075652
17921258 42642822 18935923
40140275 17921258 18935949
44573044 38139831 12899467
38139831 1321655 12899468
11223983 1788656 12920946
1788656 21905607 12921040
1357565 8148234 801402
8148234 46556089 801498
30929735 303373 19105532
31258424 30929735 19105543
34899776 9929507 6990057
9929507 49221343 6990078
49779853 43951357 25306335
41120244 49779853 25306424
6177313 41551055 25343755
24462722 6177313 25343804
16392217 32915797 31472388
32915797 19696674 31472479
6834305 36264354 25440771
44983650 6834305 25440800
26559923 47360227 19356637
47360227 49749757 19356700
33018256 36233269 37654651
36233269 5459333 37654671
6932997 23123567 25502355
23123567 7882426 25502356
5878434 43421728 25510707
43421728 40827189 25510765
38695636 33504665 1099515
13504170 38695636 1099605
32832720 40188845 37689854
8335398 32832720 37689927
35858995 41917651 1130028
41917651 28797444 1130096
47102665 6796460 43806189
6796460 6113288 43806229
21248273 5422675 43819677
48011830 21248273 43819728
32187324 39177373 25624030
39177373 42539402 25624102
41722647 14351373 25626925
14351373 45070518 25627013
22298566 25860163 37862683
2273777 22298566 37862692
10617763 32776583 7561272
35581425 10617763 7561279
18526541 18709244 31960780
18709244 32777622 31960867
36976439 24222624 31973215
24222624 9534777 31973262
25751007 11612449 38066826
43652333 25751007 38066923
8303520 2615666 7633297
2615666 29961938 7633357
22317573 31811902 31982722
14298221 22317573 31982819
43089781 7653813 44154683
8732322 43089781 44154769
24227311 43800700 13711475
40906680 24227311 13711539
48061947 30109196 7660402
43993467 48061947 7660488
29580639 5292950 38140285
5292950 21293538 38140356
17646232 47737600 32058831
47737600 42934248 32058836
13262640 23462343 1617194
23462343 1901587 1617259
5150775 7046596 44270140
7046596 22819218 44270181
17749796 34924638 32171251
8386063 17749796 32171346
30095973 12202864 38257881
12202864 42679593 38257912
10353022 40646034 26158412
40646034 36237182 26158412
8416485 16245525 32223010
16245525 32420032 32223081
20420340 1371966 7893319
1371966 2031617 7893335
2864137 20279212 26199008
29145409 2864137 26199080
29141766 19729396 44433106
44115780 29141766 44433141
6513924 34515379 32283579
12686666 6513924 32283636
20116056 49736865 44464394
49736865 47918939 44464416
38212450 3465543 32302772
3465543 39217131 32302873
12019664 37367876 44485630
3639658 12019664 44485639
18053021 1279896 7973955
2220749 18053021 7974031
19701732 12984505 1857435
24625926 19701732 1857528
9876789 34881917 26285125
27687743 9876789 26285134
5696632 6064263 44534580
34888313 5696632 44534629
14865531 46418593 38457138
5929897 14865531 38457191
44378135 4051962 38485208
4051962 10804515 38485308
11865822 21793388 14142622
7760360 11865822 14142649
32333570 24478420 44702533
24478420 23749609 44702588
29098286 25015092 44723985
32171647 29098286 44723985
20522503 20522503 2127735
20522503 20522503 2127735
22597975 20938239 8260902
20938239 48618802 8260905
8310032 34659671 2153994
34659671 25406149 2154075
49085033 5708432 26644257
5708432 32265692 26644305
18751513 18226037 32726402
18226037 33885794 32726424
45877488 23211339 20566948
23211339 26209405 20567002
48554034 25770643 38853402
9683274 48554034 38853467
9770420 14556349 2309265
27255587 9770420 2309324
32926392 16744099 44954824
24840989 32926392 44954840
29066838 49434549 26755357
49434549 12635292 26755407
21927714 32352409 20626921
32352409 15895076 20626932
7422009 23559357 14550898
32743911 7422009 14550982
38816601 5850890 26851026
5850890 32996623 26851107
42148171 47021378 26872907
47021378 32628418 26872908
9850929 10501741 32998960
10501741 24899993 32999043
27491904 4393602 33033499
4393602 17712085 33033570
37978226 42226216 39114479
42226216 2511412 39114525
42859989 49908919 45241083
48131208 42859989 45241088
39753103 30674979 14807321
30674979 45637890 14807371
30154199 11988643 2641926
11988643 11241926 2641976
7191871 13518594 45370275
13518594 45354921 45370344
54745 19711137 8871851
24814115 54745 8871937
38770495 34574748 2756244
41962321 38770495 2756337
26229406 39306415 21057327
10735951 26229406 21057347
46704290 11506122 39359422
18181795 46704290 39359481
38796645 28410469 45452212
28410469 13478996 45452222
412456 27727741 39466147
27727741 19639136 39466226
24470627 13030982 21266756
13030982 21713410 21266825
6058593 23139172 27435254
19236012 6058593 27435303
14457750 39190113 39701131
30253141 14457750 39701227
26898421 39016446 45812750
40952330 26898421 45812829
18647206 27663400 45817956
27663400 21728474 45817989
5559358 41319001 33664547
41319001 37210583 33664636
29066692 30653068 39759813
30653068 38963132 39759856
12086617 49971187 3232640
49971187 32302154 3232649
12008399 13656671 3239395
43088998 12008399 3239439
10061612 38594475 39804389
38594475 6327106 39804405
16703379 21150436 39851057
21150436 34093320 39851136
1035486 4199407 3314170
26974438 1035486 3314196
21869320 14532221 33851404
15208937 21869320 33851473
38840190 4742355 3402401
4742355 46055869 3402462
34432016 8734566 39966972
27614117 34432016 39967002
9988172 49209666 46063078
49209666 29374155 46063087
3208946 47030309 21722002
47030309 39809983 21722030
10928661 46423741 3496854
46423741 29486710 3496862
42464855 22978174 46154827
22978174 3814497 46154901
47090840 16768393 46169667
39523858 47090840 46169714
28186104 11618234 34024001
11618234 33711158 34024019
45471813 37332848 3585557
37332848 4607526 3585600
14885742 38990612 15863749
38990612 3710491 15863779
42391514 33643913 22005928
33643913 32254640 22006022
4299590 19482026 34202327
19482026 35838894 34202406
24298776 16276160 3858885
16276160 3198758 3858958
29322567 12536696 40433239
12536696 26083938 40433317
16080151 9648322 22221443
9648322 43846385 22221458
999302 19218350 10078183
10296062 999302 10078189
40544377 34492433 34463953
19908418 40544377 34463993
10765321 45143043 34542584
39154522 10765321 34542646
48642526 31097951 4104790
2940654 48642526 4104887
26972730 47422139 46846889
39228577 26972730 46846901
13788696 11503551 34728076
11503551 9151627 34728130
8676030 30463644 10406398
15204754 8676030 10406405
42984277 41087708 34805119
48741576 42984277 34805143
29634598 2151247 22699609
12264074 29634598 22699614
47525963 48470003 16667878
48470003 4566846 16667953
9725907 43325112 4498307
26465445 9725907 4498368
306967 11708860 10633595
11708860 31017081 10633669
39420965 46595640 41089015
46595640 41260374 41089048
29232745 39705052 16754836
4739295 29232745 16754840
35246405 42811088 41273637
48986699 35246405 41273719
2398239 36985098 35181790
36985098 7460784 35181841
18955749 23678549 35221035
47264406 18955749 35221129
18105816 26003002 17044057
26003002 17467477 17044087
14430126 46039962 47492180
46039962 29118827 47492275
30329324 40926812 41425850
43304610 30329324 41425912
34966996 36567528 17095113
3967517 34966996 17095144
42829171 42530474 23209891
25923738 42829171 23209967
28187681 26297990 35474412
48986691 28187681 35474475
5707126 41598794 17298139
40466899 5707126 17298188
28838696 30725820 5142797
30725820 35360418 5142798
44642019 42570370 17339657
42570370 19022469 17339727
42193681 8389736 17386517
48906013 42193681 17386586
42303185 30337820 41795129
30337820 42473956 41795170
30935782 8441903 17515229
41549758 30935782 17515275
41239019 10011768 23619001
10011768 25386353 23619062
494288 13341166 29815779
49113152 494288 29815876
7106674 26227442 29833029
47459682 7106674 29833047
17246497 35389391 17628365
35389391 34005133 17628371
23347674 48243185 17792799
48243185 22907892 17792836
21852744 1662414 36088704
8040124 21852744 36088775
32384657 27122374 36100767
24980361 32384657 36100782
31016207 26300043 42222489
26300043 36869529 42222544
17178756 44315094 42223989
44315094 11222466 42224042
34139317 39164101 36197907
39164101 27563542 36197947
31638631 22215137 17999735
22215137 10771707 17999769
30257199 32883043 24127009
32883043 179099 24127047
47774058 17451960 30283073
44583527 47774058 30283162
13816647 12695130 24145102
12695130 42284941 24145188
42749234 20004242 5893793
20004242 38129713 5893819
22210359 22178109 18109989
22178109 112961 18110049
42509645 28599506 42508465
28599506 3722411 42508513
34412629 22547405 48610262
22547405 16664124 48610296
2330283 32267749 24256113
35915758 2330283 24256157
44560231 49353986 12101694
6471293 44560231 12101780
23289721 8186827 30407293
10624448 23289721 30407389
12329357 35765163 30560085
4511908 12329357 30560158
31332240 39704929 12269193
39704929 47770487 12269249
22286152 22082044 36734758
22082044 25076919 36734833
47381309 9459604 36735886
9459604 31071680 36735890
43832763 45342283 30707519
45342283 26992816 30707602
2883029 18642608 42989696
14697025 2883029 42989793
15149987 40746227 24700535
40746227 34776566 24700549
2387554 49015265 43057085
49015265 21103141 43057139
23057202 13308993 30982514
34596334 23057202 30982553
44598498 31714790 43285828
18170064 44598498 43285841
38273701 11976319 31179763
15344094 38273701 31179764
3651338 27427037 37188945
12876654 3651338 37189007
10081580 3418061 37221143
3418061 38353019 37221143
172544 18699860 37295343
824744 172544 37295372
13914 8890169 37303853
8890169 14008003 37303898
18716557 29456130 49605004
29456130 16390535 49605083
15398102 22446674 43711290
22446674 38760679 43711383

Cではこれが1桁速くなると確信していますが、おそらくそうするのに時間はかかりません。


2
あなたの出力が正確かどうかはわかりません。最初の2行を見てみましょうA = D = 8455767、しかしU = 50175T = 50130などT - U = -45
James_pic

2

C#-30秒

私が正しく読んだ場合のほとんどのアプローチとは異なります-私はハッシュベースの構造を使用しません。

結果が得られない傾向があります。これが統計的な異常なのか、私の推論の誤りなのかはわかりません。 修正され、バイナリソートの比較に欠陥がありました。

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace FilterFile
{
    class Program
    {
        const int COUNT = 50000000;

        static string inputFile = "data" + COUNT + ".txt";
        static string outputFile = "results.txt";

        static void Main(string[] args)
        {
            Console.WriteLine("Prepping Test");
            if (args.Length > 0) inputFile = args[0];
            if (args.Length > 1) outputFile = args[1];

            if (!File.Exists(inputFile))
            {
                Console.WriteLine(inputFile);

                File.WriteAllLines(inputFile,
                                     GenerateData(COUNT)
                                     .Select(r => string.Format("{0} {1} {2}", r.A, r.B, r.C)));
            }

            File.Delete("results.txt");

            Console.WriteLine("Starting Test \n\n");

            using (Timer.Create("Total Time"))
            {
                Row[] sortedA, sortedB;
                //http://codegolf.stackexchange.com/questions/26643/filter-a-large-file-quickly
                using (Timer.Create("Reading Data"))
                    FillData(out sortedA, out sortedB);

                using (Timer.Create("Parallel Sort A"))
                    ParallelSort.QuicksortParallel(sortedA);
                using (Timer.Create("Parallel Sort B"))
                    ParallelSort.QuicksortParallel(sortedB, (x, y) => x.B - y.B);

                object rLock = new object();
                List<Row> results = new List<Row>();

                var comparison = Comparer<Row>.Create((B, A) => B.B - A.A);
                using (Timer.Create("Compute Results"))
                    Parallel.ForEach(sortedA, row =>
                    //foreach (var row in sortedA)
                    {
                        var i = Array.BinarySearch(sortedB, row, comparison);
                        if (i < 0) return;

                        Row other;
                        bool solved = false;
                        for (var tempI = i; tempI < sortedB.Length && row.A == (other = sortedB[tempI]).B; tempI++)
                        {
                            var diff = row.C - other.C;
                            if (diff >= 0 && diff < 100)
                            {
                                lock (rLock) results.Add(row);
                                return;
                            }
                        }

                        for (var tempI = i - 1; tempI >= 0 && row.A == (other = sortedB[tempI]).B; tempI--)
                        {
                            var diff = row.C - other.C;
                            if (diff >= 0 && diff < 100)
                            {
                                lock (rLock) results.Add(row);
                                return;
                            }
                        }
                    });

                using (Timer.Create("Save Results"))
                {
                    File.WriteAllLines(outputFile, results.Select(r => r.ToString()));
                }
            }
        }

        private static void FillData(out Row[] sortedA, out Row[] sortedB)
        {
            var tempA = new Row[COUNT];
            var tempB = tempA;//new Row[COUNT];

            const int PARTITION_SIZE = 1 << 22;

            ReadAndSort(tempA, tempB, PARTITION_SIZE);

            sortedA = tempA;
            sortedB = new Row[COUNT];
            Array.Copy(sortedA, sortedB, COUNT);
            /*using (Timer.Create("MergeA"))
            {
                int destIndex = 0;
                int[][] partitions = Enumerable.Range(0, COUNT / PARTITION_SIZE + 1)
                    .Select(i => new[] { i * PARTITION_SIZE, Math.Min(i * PARTITION_SIZE + PARTITION_SIZE, COUNT) - 1 })
                    .ToArray();

                for (int i = 0; i < COUNT; i++)
                {
                    foreach (var partition in partitions)
                    {
                        while (partition[0] <= partition[1] && tempA[partition[0]].A == i)
                        {
                            sortedA[destIndex++] = tempA[partition[0]++];
                        }
                    }
                }
            }*/

            /*//Verify Paritioning Works
            var results = new List<Tuple<Row, int>> { Tuple.Create(tempA[0], 0) };
            for (int i = 1; i < tempA.Length; i++)
            {
                var r = tempA[i];
                if (r.A < tempA[i-1].A)
                    results.Add(Tuple.Create(r, i % PARTITION_SIZE));
            }
            results.ForEach(t => Console.WriteLine(t.Item1 + " " + t.Item2));*/
        }

        private static void ReadAndSort(Row[] tempA, Row[] tempB, int PARTITION_SIZE)
        {
            List<Task> tasks = new List<Task>();

            using (var stream = File.OpenRead(inputFile))
            {
                int b;
                int tempMember = 0;
                int memberIndex = 0;
                int elementIndex = 0;

                using (Timer.Create("Read From Disk"))
                    while ((b = stream.ReadByte()) >= 0)
                    {
                        switch (b)
                        {
                            case (byte)'\r':
                            case (byte)' ':
                                switch (memberIndex)
                                {
                                    case 0: tempA[elementIndex].A = tempMember; memberIndex = 1; break;
                                    case 1: tempA[elementIndex].B = tempMember; memberIndex = 2; break;
                                    case 2: tempA[elementIndex].C = tempMember; memberIndex = 0; break;
                                }
                                tempMember = 0;
                                break;
                            case (byte)'\n':
                                /*if (elementIndex % PARTITION_SIZE == 0 && elementIndex > 0)
                                {
                                    var copiedIndex = elementIndex;
                                    tasks.Add(Task.Run(() =>
                                    {
                                        var startIndex = copiedIndex - PARTITION_SIZE;
                                        Array.Copy(tempA, startIndex, tempB, startIndex, PARTITION_SIZE);
                                        ParallelSort.QuicksortSequentialInPlace(tempA, startIndex, copiedIndex - 1);
                                        ParallelSort.QuicksortSequentialInPlace(tempB, startIndex, copiedIndex - 1, (x, y) => x.B - y.B);
                                    }));
                                }*/
                                elementIndex++;
                                break;
                            default:
                                tempMember = tempMember * 10 + b - '0';
                                break;
                        }
                    }

                /* tasks.Add(Task.Run(() =>
                 {
                     elementIndex--;  //forget about the last \n
                     var startIndex = (elementIndex / PARTITION_SIZE) * PARTITION_SIZE;
                     Array.Copy(tempA, startIndex, tempB, startIndex, elementIndex - startIndex + 1);
                     ParallelSort.QuicksortParallelInPlace(tempA, startIndex, elementIndex);
                     ParallelSort.QuicksortSequentialInPlace(tempB, startIndex, elementIndex, (x, y) => x.B - y.B);
                 }));

                 using (Timer.Create("WaitForSortingToFinish"))
                     Task.WaitAll(tasks.ToArray());*/
            }
        }

        static Random rand = new Random();

        public struct Row : IComparable<Row>
        {
            public int A;
            public int B;
            public int C;
            public static Row RandomRow(int count)
            {
                return new Row { A = rand.Next(count), B = rand.Next(count), C = rand.Next(count) };
            }

            public int CompareTo(Row other)
            {
                return A - other.A;
            }

            public override string ToString()
            {
                return string.Format("{0} {1} {2}", A, B, C);
            }
        }

        public static Row[] GenerateData(int count)
        {
            var data = new Row[count];
            for (int i = 0; i < count; i++)
                data[i] = Row.RandomRow(count);
            return data;
        }

        public static Row[] GenerateSplitData(int count)
        {
            var data = new Row[count];
            for (int i = 0; i < count; i++)
                data[i] = Row.RandomRow(count);
            return data;
        }

        public class Timer : IDisposable
        {
            string message;
            Stopwatch sw;
            public static Timer Create(string message)
            {
                Console.WriteLine("Started: " + message);
                var t = new Timer();
                t.message = message;
                t.sw = Stopwatch.StartNew();
                return t;
            }
            public void Dispose()
            {
                Console.WriteLine("Finished: " + message + " in " + sw.ElapsedMilliseconds + "ms");
            }
        }

        // <summary> 
        /// Parallel quicksort algorithm. 
        /// </summary> 
        public class ParallelSort
        {
            const int SEQUENTIAL_THRESHOLD = 4096;
            #region Public Static Methods

            /// <summary> 
            /// Sequential quicksort. 
            /// </summary> 
            /// <typeparam name="T"></typeparam> 
            /// <param name="arr"></param> 
            public static void QuicksortSequential<T>(T[] arr) where T : IComparable<T>
            {
                QuicksortSequentialInPlace(arr, 0, arr.Length - 1);
            }

            /// <summary> 
            /// Parallel quicksort 
            /// </summary> 
            /// <typeparam name="T"></typeparam> 
            /// <param name="arr"></param> 
            public static void QuicksortParallel<T>(T[] arr) where T : IComparable<T>
            {
                QuicksortParallelInPlace(arr, 0, arr.Length - 1);
            }

            #endregion

            #region Private Static Methods

            public static void QuicksortSequentialInPlace<T>(T[] arr, int left, int right)
                where T : IComparable<T>
            {
                if (right > left)
                {
                    int pivot = Partition(arr, left, right);
                    QuicksortSequentialInPlace(arr, left, pivot - 1);
                    QuicksortSequentialInPlace(arr, pivot + 1, right);
                }
            }

            public static void QuicksortParallelInPlace<T>(T[] arr, int left, int right)
                where T : IComparable<T>
            {
                if (right > left)
                {
                    if (right - left < SEQUENTIAL_THRESHOLD)
                        QuicksortSequentialInPlace(arr, left, right);
                    else
                    {
                        int pivot = Partition(arr, left, right);
                        Parallel.Invoke(() => QuicksortParallelInPlace(arr, left, pivot - 1),
                                        () => QuicksortParallelInPlace(arr, pivot + 1, right));
                    }
                }
            }

            private static void Swap<T>(T[] arr, int i, int j)
            {
                T tmp = arr[i];
                arr[i] = arr[j];
                arr[j] = tmp;
            }

            private static int Partition<T>(T[] arr, int low, int high)
                where T : IComparable<T>
            {
                // Simple partitioning implementation 
                int pivotPos = (high + low) / 2;
                T pivot = arr[pivotPos];
                Swap(arr, low, pivotPos);

                int left = low;
                for (int i = low + 1; i <= high; i++)
                {
                    if (arr[i].CompareTo(pivot) < 0)
                    {
                        left++;
                        Swap(arr, i, left);
                    }
                }

                Swap(arr, low, left);
                return left;
            }

            #endregion

            #region Public Static Methods

            /// <summary> 
            /// Sequential quicksort. 
            /// </summary> 
            /// <typeparam name="T"></typeparam> 
            /// <param name="arr"></param> 
            public static void QuicksortSequential<T>(T[] arr, Func<T, T, int> comparer)
            {
                QuicksortSequentialInPlace(arr, 0, arr.Length - 1, comparer);
            }

            /// <summary> 
            /// Parallel quicksort 
            /// </summary> 
            /// <typeparam name="T"></typeparam> 
            /// <param name="arr"></param> 
            public static void QuicksortParallel<T>(T[] arr, Func<T, T, int> comparer)
            {
                QuicksortParallelInPlace(arr, 0, arr.Length - 1, comparer);
            }

            #endregion

            #region Private Static Methods

            public static void QuicksortSequentialInPlace<T>(T[] arr, int left, int right, Func<T, T, int> comparer)
            {
                if (right > left)
                {
                    int pivot = Partition(arr, left, right, comparer);
                    QuicksortSequentialInPlace(arr, left, pivot - 1, comparer);
                    QuicksortSequentialInPlace(arr, pivot + 1, right, comparer);
                }
            }

            public static void QuicksortParallelInPlace<T>(T[] arr, int left, int right, Func<T, T, int> comparer)
            {
                if (right > left)
                {
                    if (right - left < SEQUENTIAL_THRESHOLD)
                    {
                        QuicksortSequentialInPlace(arr, left, right, comparer);
                    }
                    else
                    {
                        int pivot = Partition(arr, left, right, comparer);
                        Parallel.Invoke(() => QuicksortParallelInPlace(arr, left, pivot - 1, comparer),
                                        () => QuicksortParallelInPlace(arr, pivot + 1, right, comparer));
                    }
                }
            }

            private static int Partition<T>(T[] arr, int low, int high, Func<T, T, int> comparer)
            {
                // Simple partitioning implementation 
                int pivotPos = (high + low) / 2;
                T pivot = arr[pivotPos];
                Swap(arr, low, pivotPos);

                int left = low;
                for (int i = low + 1; i <= high; i++)
                {
                    if (comparer(arr[i], pivot) < 0)
                    {
                        left++;
                        Swap(arr, i, left);
                    }
                }

                Swap(arr, low, left);
                return left;
            }
            #endregion
        }
    }
}

入力データのサイズに関係なく、多かれ少なかれ約200の結果が得られるはずです。私はあなたがそれを想定している疑いがある-私はあなたの問題はライン98-102に、あなたはバイナリ検索を使用している方法に関係している疑いがあるx.Aから来るsortedA、とx.Bから来るsortedBの両方から来る実際には、一方sortedB、これがComparer生成されますナンセンスな結果。
James_pic 2014年

より一般的には、ABで並べ替える場合、反復Aとバイナリ検索よりも高速なアルゴリズムがBありますO(n log(n))(実際には貧乏人のハッシュテーブルです)。代わりに、2つのリストをマージ結合できますO(n)
James_pic 2014年

別の楽しいオプションは、の値がB特定の範囲に均一に分布することを知っているので、バイナリ検索を補間検索にスワップO(log(n))することO(log(log(n))です。これにより、検索時間がからに短縮されます。
James_pic 2014年

@James_pic提案に感謝します。時間があれば、追跡します。私はIOを奇数秒で40秒削減したので、並べ替えと計算に再び集中できます。
NPSF3000 2014年

比較器が修正され、結果が生成されました。計算は30分の約5秒(入力12、ソート5それぞれ)しか占めていないので、次の攻撃ラインについて考えています。IOは約100MBpsで処理しているため、スピードアップが制限される可能性があります。
NPSF3000 2014年

1

C

残忍な、力ずくの、醜い醜いC.やり直しの際には、他のコンパイル済み言語を選択します。

/*
Filter a file based on these rules:

Input:
    - each item is an ordered list of three integers ( A B T )
    - each line represents an item
    - each line is formated as <number> <w> <number> <w> <number>
    - <w> is whitespace (a single blank in the challenge)
    - <number> is an integer in the range 0..49_999_999
    - the first number on a line is A, second B, third T

Output a given item ( A B T ) if:
    1 - there exists an item ( C D U ) such that 0 <= T-U < 100 and D == A 
    OR
    2 - there exists an item ( C D U ) such that 0 <= U-T < 100 and B == C 

CLARIFICATION:
An item should be output only once, even if there is more than one match.

We're sorting on T, we know the number of Ts to be sorted and the Ts are random.
Trade space for speed and create a lookup table that can handle collisions
(AKA hash table).
*/

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <pthread.h>
#include <assert.h>


#define NTHREADS    (16)
#define BINSPERTHREAD   (1*1000*1000)
bool    oneThread = false;

typedef struct {
    pthread_t   tid;
    long        begin;
    long        end;
} threadState;

void *initTID() {
    return NULL;
}


#define MAXITEMS    (50*1000*1000)
//  items on the boundary are not included in the search
#define SEARCHBOUNDARY  (100)


void usage(char *name) {
    fprintf(stderr, "usage: %s [-n 1..%d]\n", name, MAXITEMS);
}

typedef struct item {
    long    A;
    long    B;
    long    T;
    bool    unprinted;
    struct item *b;         // b(ackward to previous item)
    struct item *f;         // f(orward to next item)
    struct item *BINb;          // backward to previous bin
    struct item *BINf;          // forward to next bin
#ifdef DEVTEST
    long    lineNumber;
#endif
} item;
#ifdef DEVTEST
bool    printVerbose = false;
#endif


//  Why global variables? Because large MAXITEMS overflow the stack.
long    maxItems;           // entries allocated in list & lookup
item    *list;
long    listN;              // number of entries (max index + 1)
item    **lookup;
long    lookupN;            // number of entries (max index + 1)


/*
input -
    n       - index of current bin
    list        - global
    lookup      - global
    lookupN     - global
side-effects -
    list[] (.unprinted)
    stdout
*/
static inline void *walkThisBin(long n) {
    item    *p;
    item    *searchHead;
    item    *searchTail;
    item    *currentItem;
    long    i;

    //  for all items in bin
    for ( currentItem = lookup[n]; currentItem != lookup[n]->BINf;
        currentItem = currentItem->f)
    {
    /*
        merged forward&backward search
    */
    searchHead = currentItem;
    //  step to index min((T+100-1),lookupN-1), find largest U<T+100
    i = ((n+SEARCHBOUNDARY-1) < lookupN) ?
        n+SEARCHBOUNDARY-1 :
        lookupN-1;
    //  find largest i such that U-T<100 (U is lookup[i]->T)
    //  degenerate case is i == n
    for(p=lookup[i];
        !((p->T-searchHead->T)<SEARCHBOUNDARY);
        p=lookup[i]) {
        i--;
    }
    searchTail = p->BINf;       // boundary, not included in search
    p = currentItem;
    do {
        if (searchHead->B == p->A) {
        //  matches are symmetric
        if (searchHead->unprinted) {
            printf("%ld %ld %ld\n", searchHead->A, searchHead->B,
            searchHead->T);
            searchHead->unprinted = false;
        }
        if (p->unprinted) {
            printf("%ld %ld %ld\n", p->A, p->B, p->T);
            p->unprinted = false;
        }
        }
        p = p->f;
    } while (p!=searchTail);
    }
    return NULL;
}

/*
Must handle out-of-range indexes for lookup.

input -
    n       - index of current bin
    list        - global
    lookup      - global
    lookupN     - global
side-effects -
    list (.unprinted)
    stdout
*/

static inline void *walkTheseBins(void *tState) {
    long    startIndex = ((threadState *)tState)->begin;
    long    finishIndex = ((threadState *)tState)->end;
    long    n;

    startIndex = (startIndex<0) ? 0 : startIndex;
    finishIndex = (finishIndex>lookupN-1) ? lookupN-1 : finishIndex;
    for (n=startIndex; n<=finishIndex; n++) {
    walkThisBin(n);
    }
    return NULL;
}


int main(int argc, char *argv[]) {
#ifdef DEVTEST
item    *head;
item    *tail;
long    count = 0;
#endif
    //  subroutines? subroutines? we don't need no stinkin' subroutines
    //  this is all the scoping you're going to need
    //                      ... truuuuust me
    /*
    Allocate list[] and lookup[]. Set maxItems.

    input -
        argc
        argv
    side-effects -
        list
        lookup
        maxItems
        malloc()
        DEVTEST stuff
    */
    {
    int c;          // option character

    maxItems = MAXITEMS;
    while ((c = getopt(argc, argv, ":n:sv")) != -1) {
        switch(c) {
#ifdef DEVTEST
        case 'v':
        //  print some reassuring messages
        printVerbose = true;
        break;
#else
        case 'v':
        fprintf(stderr, "unknown option -%c\n", optopt);
        usage(argv[0]);
        exit(1);
        break;
#endif
        case 'n':
        if (sscanf(optarg, "%ld", &maxItems) != 1) {
            fprintf(stderr, "-n argument \"%s\" unscannable\n", optarg);
            usage(argv[0]);
            exit(1);
        }
        break;
        case 's':
        //  use only one thread?
        oneThread = true;
        break;
        case ':':           // -s needs an argument
        usage(argv[0]);
        exit(1);
        break;
        case '?':           // not a valid option
        fprintf(stderr, "unknown option -%c\n", optopt);
        usage(argv[0]);
        exit(1);
        break;
        }
    }
    if ((maxItems<1) || (maxItems>MAXITEMS)) {
        fprintf(stderr, "-s argument \"%ld\" out of range\n", maxItems);
        usage(argv[0]);
        exit(1);
    }
    list = (item *) malloc(sizeof(item) * maxItems);
    if (list == NULL) {
        fprintf(stderr, "ERROR: list = malloc() failure\n");
        exit(1);
    }
    lookup = (item **) malloc(sizeof(item *) * maxItems);
    if (lookup == NULL) {
        fprintf(stderr, "ERROR: lookup = malloc() failure\n");
        exit(1);
    }
    }

    /*
    Convert STDIN into an array of items.

    input -
        list
        lookup
        maxItems
    side-effects -
        list
        lookup
        listN
        stdin
    */
    {
    long    largestT = 0;
    item    x;

    for (listN=0; scanf("%ld%ld%ld", &x.A, &x.B, &x.T)==3; listN++) {
        if (listN == maxItems) {
        fprintf(stderr, "ERROR: > %ld input items read\n", maxItems);
        exit(1);
        }
        x.b = x.f = NULL;
        x.unprinted = true;
        x.BINb = x.BINf = NULL;
        largestT = (x.T>largestT) ? x.T : largestT;
#ifdef DEVTEST
        x.lineNumber = listN + 1;
#endif
        list[listN] = x;
    }
    if (!feof(stdin)) {
        fprintf(stderr, "ERROR: ferror() = %d\n", ferror(stdin));
        exit(1);
    }
    //  Be paranoid. Because cores are obnoxious.
    if (largestT>=maxItems) {
        fprintf(stderr, "ERROR: T:%ld > %ld \n", largestT, maxItems-1);
        exit(1);
    }
    }
#ifdef DEVTEST
(printVerbose) && printf("in: %ld\n", listN);
#endif
    //  Short-circuit on 0 items. Simplifies things like finding the head.
    if  (listN == 0) {
    exit(0);
    }

    /*
    Populate the lookup table. Build a doubly linked list through it.

    input -
        list
        lookup
        listN
    side-effects -
        list[]
        lookup[]
        lookupN
        DEVTEST stuff
    */
    {
    long    n;

    /*
        Populate the lookup table. The lookup table is an array-of-lists.
    The lists are LIFO. This is the most primitive of hashes, where the
    key, item.T, is used as the index into the lookup table.
    */
    for (n=0; n<maxItems; n++) {
        lookup[n] = NULL;
    }
    for (n=0; n<listN; n++) {
        long    t = list[n].T;

        if (lookup[t] == NULL) {
        lookup[t] = &(list[n]);
        } else {
        // collision
        list[n].f = lookup[t];  // forward pointer assigned
        lookup[t] = &(list[n]);
        }
    }
    /*
        Collapse lookup to squeeze out NULL references. This breaks
    the linear mapping between T value & lookup index, but worth it for
    simpler search logic. Build a doubly linked list of bins.
    */
    item    *previousBin = NULL;    // last non-NULL lookup entry
    lookupN = 0;
    for (n=0; n<maxItems; n++) {
        if (lookup[n] != NULL) {
        lookup[lookupN] = lookup[n];
        lookup[lookupN]->BINb = previousBin;
        if (previousBin) {
            previousBin->BINf = lookup[lookupN];
        }
        previousBin = lookup[lookupN];
        lookupN++;
        }
    }
    previousBin->BINf = NULL;

    /*
        Build a doubly linked list. The forward pointers already exist
    within each lookup table bin.
    */
    item    *p;
    item    *binHead;
    item    *previous;

    //  create a loop in each bin
    for (n=0; n<lookupN; n++) {
#ifdef DEVTEST
count++;
#endif
        binHead = lookup[n];
        for (p=binHead; p->f; p=p->f) {
        p->f->b = p;
#ifdef DEVTEST
count++;
#endif
        }
        p->f = binHead;
        binHead->b = p;
    }
    //  break the loops and connect them tail-to-head
#ifdef DEVTEST
head = lookup[0];
#endif
    previous = NULL;
    for (n=0; n<lookupN; n++) {
        binHead = lookup[n];
        p = binHead->b;     // p => tail of this bin list
        binHead->b = previous;  // connect bin head to list
        if (previous) {     // connect list to bin head
        previous->f = binHead;
        }
        previous = p;
    }
    previous->f = NULL;
#ifdef DEVTEST
tail = previous;
#endif
    }

#ifdef DEVTEST
if (printVerbose) {
    printf("out: %ld\n", count);

    //  run through the list forwards
    item    *p;
    count = 0;
    for (p=head; p; p=p->f) {
    count++;
    }
    printf("forwards: %ld\n", count);
    //  run through the list backwards
    count = 0;
    for (p=tail; p; p=p->b) {
    count++;
    }
    printf("backwards: %ld\n", count);
    /*
        //  print the list
        for (p=head; p; p=p->f) {
        printf("%ld %ld %ld\n", p->A, p->B, p->T);
        }
    */
}
#endif

    /*
    Find matches & print.

    (authoritative statement)
    Print item ( A B T ) if:
    1 - there exists an item ( C D U ) such that 0 <= T-U < 100 and D == A 
        OR
    2 - there exists an item ( C D U ) such that 0 <= U-T < 100 and B == C 


    TBD
    - threading


    input -
        lookupN
    side-effects -
        lots hidden in walkTheseBins(), all thread-local or thread-safe
    */
    {
    volatile threadState    tState[NTHREADS]; // use as cicular buffer
    long                h;  // cicular buffer head
    long                n;

    if (oneThread) {
        tState[0].begin = 0;
        tState[0].end = lookupN-1;
        walkTheseBins((void *)tState);
    } else {
        //  every slot has a thread to wait for
        for (h=0; h<NTHREADS; h++) {
        assert( pthread_create(&(tState[h].tid), NULL, initTID, NULL) == 0);
        }
        h = 0;
        for (n=0; n<lookupN+BINSPERTHREAD; n+=BINSPERTHREAD) {
        pthread_join(tState[h].tid, NULL);
        tState[h].begin = n;
        tState[h].end = n + BINSPERTHREAD - 1;
        assert( pthread_create(&(tState[h].tid), NULL, walkTheseBins, (void *)(tState+h)) == 0);
        h = (h + 1) % NTHREADS;
        }
        //  wait for any remaining threads
        for (h=0; h<NTHREADS; h++) {
        pthread_join(tState[h].tid, NULL); // may have already join'ed some
        }
    }
    }

    return 0;
}

「gcc -m64 -pthreads -O」でコンパイルします。stdinへの入力が必要です。デフォルトでマルチスレッドで実行されます。「-s」オプションを使用して、1つのスレッドのみを使用します。


警告が表示されます:形式 '%d'はタイプ 'int'の引数を予期していますが、引数3のタイプは 'long int'です[-Wformat =] fprintf(stderr、 "ERROR:T:%d>%d \ n"、maximumT 、listN-1);

@Lembikコンパイラ警告のソースを編集しました。メイクファイルに追加します。投稿の最後に使い方の文章も追加しました。スレッド化されたバージョンが来るのですが、あなたのマシンでスレッド化されていないパフォーマンスのパフォーマンスチェックを取得したいと思います。
Scott Leadley 2014年

このコードは私には奇妙に遅いです(問題のタイミングを参照してください)。それはあなたのためのJava提出または他のC提出とどのように比較しますか?

コードでTU = 0が許可されていないと思います。行18662170 45121353 3365641(改行)44329255 18662170 3365641のみを含むファイルでテストしたかったのですが、エラーが返されます。

@Lembikああ、Tは入力の行数ではなく、50M未満でなければなりません。私はそれを修正し、スレッドを追加しました。
Scott Leadley 2014年

1

ようやくLembikに似た物理的なUbuntu 14.04システムを構築し、このパズルの解決策について検死を行う機会を得ました。私の重要な選択では:

  1. 本当のマスターはJames_picです。彼は時期尚早に最適化しなかったからです。
    • 彼は計画を持っていた
    • 彼は高レベルの抽象化(スカラ)で計画を実行し、そこで洗練させました
    • 彼はそれをCでさらに洗練させた
    • 彼はそれを過度に洗練しませんでした(次のポイントを参照)
  2. ファイルシステムのI / O時間は、おそらくターゲットシステムの経過時間の下限です。
    • レンビックはこれをほのめかしている、すなわち「勝者はどちらもwcとほとんど同じくらい速い!」
  3. 私の元のソリューションがうまくいかなかった理由のいくつかはパフォーマンスがよくなかった:
    • 参照の局所性は、ターゲットシステムの主要な要素です。
    • ハッシュソートを行う場合は、AまたはBでソートすることをお勧めします。Tでの並べ替えは、少なくとも私が行った方法で、ハッシュの並べ替えに複雑さ(およびキャッシュに敵対的な間接性)を追加します。
    • Scanf()は豚です。
    • ボトルネックが存在する場所では、帯域幅(ディスク->メモリ->キャッシュ)が大きく変化します。ターゲットシステムに大きな帯域幅がありません。(次のポイントを参照)
  4. 迅速な開発は、ターゲット環境で行われた場合に最もよく機能します。
    • ああ!しかし、私はもともとSolaris / SPARCに悩まされ、それ以外の方法ではプレイできませんでした。
    • 仮想化されたSAN環境でキャッシュの影響を排除することは困難です。
    • 通常、Linux VMにも同じ問題があります。
  5. 少し数学が役立ちます。
    • ハッシュテーブルから1つのタプルを直接フェッチすると、間接参照の可能性が約37%(〜1 / e)に削減されます。
    • ハッシュテーブルから2つのタプルを直接フェッチすると、オーバーフローテーブルへの参照が最大10%カットされます。必要ありませんでした。
  6. 32ビットメモリモデル(gcc -m32)は注意散漫です。
    • スレッド化されていないプログラムの小さな勝利、時には小さな損失。
    • スレッド化されたプログラムの重大な損失。
    • 32ビットが重要な場合(およびターゲットが組み込みコントローラーではない場合)、ハードウェアを更新する方が安上がりです。
    • 余分なレジスタとより大きなアドレス空間を取り、振り返ってはいけません。
  7. Scanf()は豚ですが、stdioの使用は絶望的ではありません。
    • scanf()のオーバーヘッドのほとんどは、フォーマット駆動の解析と文字列から整数への変換にあるようです。
    • sscanf()の置き換え:
      • strtok()+ atoi()は最大2倍高速です(下の表を参照)
      • strtol()は約3倍高速です
      • カスタムのローカルstrtol()は〜6.5倍高速です
      • strtol()をローカルソリューションで置き換えると、 "wc"と同等になります。
      • getc_unlocked()を使用するFSMは、Keith Randallのミニマリストmmap()ソリューションとほぼ同じ速さ
      • Cでの再実装時の実験結果[CSVで、Stack Exchangeは明らかにテーブルを実行しないため]:
        
        "solution (64-bit unless noted)","disposition of input","user","system","elapsed"
        "dd if=? of=/dev/null bs=1024k","","0.010","1.107","26.47"
        "wc {LANG=C}","","4.921","0.752","26.38"
        "","","","",""
        "fscanf()","discard","13.130","0.490","26.43"
        "fgets(), no integer conversion","discard","1.636","0.468","26.42"
        "fgets() + sscanf()","discard","16.173","0.498","26.48"
        "fgets() + strtok(), no integer conversion","discard","4.659","0.481","26.48"
        "fgets() + strtok() + atoi()","discard","8.929","0.490","26.49"
        "fgets() + strtol()","discard","6.009","0.483","26.50"
        "fgets() + custom-strtol()","discard","3.842","0.474","26.43"
        "fgets() + custom-strtol()","sort (load hash) while reading","7.118","1.207","26.70"
        "fgets() + custom-strtol()","sort, match & print","10.096","1.357","28.40"
        "fgets() + custom-strtol(), 32-bit","sort, match & print","10.065","1.159","28.38"
        "","","","",""
        "james_pic's solution","sort, match & print","9.764","1.113","28.21"
        


さらに別のFSMパーサーで退屈するのではなく、以下の解決策はfgets()とローカルのstrtol()の置き換えを使用します[s2i()を探す]。

Rubyのリファレンス実装:

#!/usr/bin/ruby2.0
# only tested against ruby v1.9 & v2.0
=begin
Filter a file based on these rules:
Input:
  - each line is a set of three integers
  - each line is formatted as <number> <w> <number> <w> <number>
    - <w> is whitespace (a single blank in the challenge)
    - <number> is an integer in the range 1..50_000_000
Output a given tuple ( A B T ) if:
  - there exists a tuple ( C D U ) 0 <= T - U < 100 and D == A
    OR
  - there exists a tuple ( C D U ) 0 <= U - T < 100 and B == C

Typical use:
  filter.rb test.input | sort | uniq > test.output
=end
list = Array.new
lookupB = Hash.new { |hash, key| hash[key] = Array.new }
ARGF.each_with_index do |line, index|
  abt = line.split.map { |s| s.to_i }
  list << abt
  lookupB[abt[1]] << index
end
for abt in list do
  for i in Array( lookupB[abt[0]] ) do
    delta = abt[2] - list[i][2]     # T - U
    if (0<=delta) && (delta<100)
      puts "#{abt.join(' ')}"
      puts "#{list[i].join(' ')}"
    end
  end
end

それは犬であり、Cソリューションより〜50倍遅いですが、perlは同じくらい遅く、簡潔ではありません。

Cソリューション:


#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
//      Throw caution, and error checking, to the winds.
// #include <assert.h>

#define RANGEMIN        (1)
#define RANGEMAX        (50*1000*1000)
#define SEARCHBOUNDARY  (100)
typedef struct {
    int             A;
    int             B;
    int             T;
} tuple_t;
typedef struct bin {
    tuple_t         slot;
    struct bin     *next;       // NULL=>0 items, self=>1 item, other=>overflow
} bin_t;
#define LISTSIZE        (RANGEMAX)
tuple_t         list[LISTSIZE];
#define HASH(x)         (x-1)
#define LOOKUPSIZE      (LISTSIZE)
bin_t           lookup[LOOKUPSIZE];
bin_t           overflow[LISTSIZE];
int             overflowNext = 0;

// based on strtol()
static inline int s2i(char *s, char **r)
{
    char            c;
    int             l = 0;

    do {
        c = *s++;
    } while (!isdigit(c));
    do {
        l = l * 10 + (c - '0');
        c = *s++;
    } while (isdigit(c));
    *r = s - 1;
    return l;
}

static inline void lookupInsert(tuple_t x)
{
    bin_t          *p = lookup + HASH(x.B);

    if (p->next) {
        overflow[overflowNext].slot = x;
        overflow[overflowNext].next = (p->next == p) ? p : p->next;
        p->next = overflow + overflowNext;
        overflowNext++;
    } else {
        p->slot = x;
        p->next = p;
    }
}

static void printOverflow(bin_t * head, bin_t * tail)
{
    if (head->next != tail) {
        printOverflow(head->next, tail);
    }
    printf("%d %d %d\n", head->slot.A, head->slot.B, head->slot.T);
}

static inline void dumpLookupSortedOnB()
{
    bin_t          *p;

    for (p = lookup; p < (lookup + LOOKUPSIZE); p++) {
        if (p->next) {
            printf("%d %d %d\n", p->slot.A, p->slot.B, p->slot.T);
            if (p != p->next) {
                printOverflow(p->next, p);
            }
        }
    }
}

static inline void printIfMatch(tuple_t abt, tuple_t cdu)
{
    int             A, B, T;
    int             C, D, U;

    A = abt.A;
    D = cdu.B;
    if (D == A) {
        T = abt.T;
        U = cdu.T;
        if ((0 <= (T - U)) && ((T - U) < SEARCHBOUNDARY)) {
            B = abt.B;
            C = cdu.A;
            printf("%d %d %d\n", A, B, T);
            printf("%d %d %d\n", C, D, U);
        }
    }
}

static inline void printMatches(int n)
{
    tuple_t        *p;

    for (p = list; p < (list + n); p++) {
        bin_t          *b = lookup + HASH(p->A);

        if (b->next) {
            bin_t          *q;

            printIfMatch(*p, b->slot);
            for (q = b->next; q != b; q = q->next) {
                printIfMatch(*p, q->slot);
            }
        }
    }
}

static inline void overflowTattle(int n)
{
    fprintf(stderr, "%d/%d items in overflow\n", overflowNext, n);
}

int main(int argc, char *argv[])
{
    int             n;

    // initialize lookup[]
    {
        bin_t          *p = lookup;

        for (n = 0; n < LOOKUPSIZE; n++) {
            p->next = NULL;
            p++;
        }
    }
    // read all tuples into list[] and insert into lookup[] & overflow[]
    {
        char            line[64];
        char           *lp;
        tuple_t        *p = list;

        for (n = 0; fgets(line, sizeof(line), stdin); n++) {
            p->A = s2i(line, &lp);
            p->B = s2i(lp, &lp);
            p->T = s2i(lp, &lp);
            lookupInsert(*p);
            p++;
        }
    }
    printMatches(n);
    exit(0);
}

「gcc -O3 -std = c99 -Wall -m64」でコンパイルします。

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.