Esempio n. 1
0
        /// <summary>
        /// Files and containers initialisation
        /// </summary>
        private void Init(int bFactor, int overflowBFactor, string mainFileDiskLetter, string overflowFileDiskLetter)
        {
            UtilityOperations.GetDiskFreeSpace(mainFileDiskLetter, out var SectorsPerCluster, out var BytesPerSector, out _, out _);
            var ClusterSize = SectorsPerCluster * BytesPerSector;

            _BFactor         = bFactor == -1 ? (ClusterSize - 8) / _emptyClass.GetSize() : bFactor;
            _OverflowBFactor = overflowBFactor == -1 ? (ClusterSize - 8) / _emptyClass.GetSize() : overflowBFactor;


            _blocksInformations = new List <BlockInfo>((int)Math.Pow(2, _hashDepth));

            var block         = new Block <T>(_BFactor, _emptyClass.GetEmptyClass());
            var overflowBlock = new Block <T>(_OverflowBFactor, _emptyClass.GetEmptyClass());

            _fileManager     = new FileManager(_filePath, block.GetSize());
            _overflowManager = new OverflowFileManager <T>("overflow." + _filePath, overflowBlock.GetSize(), _emptyClass, _OverflowBFactor);

            var address = _fileManager.GetFreeAddress();

            _blocksInformations.Add(new BlockInfo {
                Address = address, Depth = 1, Records = 0
            });
            WriteBlock(address, block);

            address = _fileManager.GetFreeAddress();
            _blocksInformations.Add(new BlockInfo {
                Address = address, Depth = 1, Records = 0
            });
            WriteBlock(address, block);
        }
Esempio n. 2
0
        public void Start()
        {
            Console.WriteLine("--- Extended Hashing Tester ---");

            UtilityOperations.GetDiskFreeSpace("C:\\", out var SectorsPerCluster, out var BytesPerSector, out var NumberOfFreeClusters, out var TotalNumberOfClusters);
            var ClusterSize = SectorsPerCluster * BytesPerSector;
            var emptyProp   = new Property();

            Console.WriteLine($"Record size: {emptyProp.GetSize()}");
            Console.WriteLine($"Cluster size: {ClusterSize}");
            var bFactor = (ClusterSize - 8) / emptyProp.GetSize();

            Console.WriteLine($"Recomended BFactor: {bFactor}");

            Console.Write($"Blocking factor (default {bFactor}): ");
            var inp = Console.ReadLine();

            bFactor = string.IsNullOrWhiteSpace(inp) ? bFactor : int.Parse(inp);

            Console.Write("File path (default file.dat): ");
            inp     = Console.ReadLine();
            inp     = String.IsNullOrWhiteSpace(inp) ? "file.dat" : inp;
            hashing = new ExtendibleHashingDirectory <Property>(inp, bFactor, 9);

            Console.Write("Seed (default is random): ");
            inp = Console.ReadLine();
            var seed = string.IsNullOrWhiteSpace(inp) ? Guid.NewGuid().GetHashCode() : int.Parse(inp);

            Console.WriteLine($"Seed = {seed}");

            rnd           = new Random(seed);
            helpStructure = new Dictionary <int, Property>();

            do
            {
                Console.WriteLine();
                PrintStats();
                Console.WriteLine();
                PrintMenu();
                GetInput();
                Console.WriteLine();
                HandleInput();
            } while (!exit);
        }