Exemple #1
0
    void ShuffleBin(string path)
    {
        using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite)) {
            CloudStream.Reader reader = new CloudStream.Reader(fs);
            CloudStream.Writer writer = new CloudStream.Writer(fs);

            byte[] tmp_i = new byte[CloudStream.pointRecSize] , tmp_j = new byte[CloudStream.pointRecSize];
            ShuffleUtility.WithSwap((int)fs.Length / CloudStream.pointRecSize,
                                    (i, j) => {
                reader.SeekPoint(i);
                tmp_i = reader.ReadBytes( tmp_i.Length);
                reader.SeekPoint(j);
                tmp_j = reader.ReadBytes( tmp_j.Length);
                writer.SeekPoint(j);
                writer.Write(tmp_i);
                writer.SeekPoint(i);
                writer.Write(tmp_j);
            });
        }
    }
Exemple #2
0
    void ShuffleSlicesAndSample(string bin_path)
    {
        using (FileStream stream = File.Open( bin_path, FileMode.Open)) {
            CloudStream.Reader reader = new CloudStream.Reader(stream);
            try {
                foreach(Slice slice in prog.Iterate(iCloud.slices)) {
                    int byteCount = slice.size * CloudStream.pointRecSize;
                    byte[] sliceBytes = new byte[byteCount];

                    reader.SeekPoint(slice.offset, SeekOrigin.Begin);
                    stream.Read( sliceBytes, 0, byteCount );

                    byte[] tmp = new byte[CloudStream.pointRecSize];
                    ShuffleUtility.WithSwap(slice.size, (i, j) =>
                    {
                        /*
                         * This is the fastest way I found to swap 16-byte long chunks in memory (tried MemoryStream and
                         * byte-by-byte swap loop).
                         */
                        System.Buffer.BlockCopy(sliceBytes, i * CloudStream.pointRecSize, tmp, 0, CloudStream.pointRecSize);
                        System.Buffer.BlockCopy(sliceBytes, j * CloudStream.pointRecSize, sliceBytes, i * CloudStream.pointRecSize, CloudStream.pointRecSize);
                        System.Buffer.BlockCopy(tmp, 0, sliceBytes, j * CloudStream.pointRecSize, CloudStream.pointRecSize);
                        // 'i' runs backwards from pointCount-1 to 0
                    });

                    reader.SeekPoint(slice.offset, SeekOrigin.Begin);
                    stream.Write( sliceBytes, 0, byteCount );

                    // may be sample
                    CloudStream.Reader mem = new CloudStream.Reader(new MemoryStream(sliceBytes));
                    int sampleSize = Math.Min( sliceSampleSize, (int)mem.PointCount );
                    mem.DecodePoints(meshConv, sampleSize );
                }
            } finally {
                prog.Done("Shuffled orig bin in {tt}");
            }
        } // using(stream)
    }