예제 #1
0
        private bool TryGetLinkMessageFromLinkInfoMessage(LinkInfoMessage linkInfoMessage,
                                                          string name,
                                                          [NotNullWhen(returnValue: true)] out LinkMessage?linkMessage)
        {
            linkMessage = null;

            var fractalHeap     = linkInfoMessage.FractalHeap;
            var btree2NameIndex = linkInfoMessage.BTree2NameIndex;
            var nameHash        = H5Checksum.JenkinsLookup3(name);
            var candidate       = default(LinkMessage);

            var success = btree2NameIndex.TryFindRecord(out var record, record =>
            {
#warning Better to implement comparison code in record (here: BTree2Record05) itself?

                if (nameHash < record.NameHash)
                {
                    return(-1);
                }
                else if (nameHash > record.NameHash)
                {
                    return(1);
                }
                else
                {
#warning duplicate2
                    using var localReader = new H5BinaryReader(new MemoryStream(record.HeapId));
                    var heapId            = FractalHeapId.Construct(this.Context, localReader, fractalHeap);
                    candidate             = heapId.Read(reader => new LinkMessage(reader, this.Context.Superblock));

                    // https://stackoverflow.com/questions/35257814/consistent-string-sorting-between-c-sharp-and-c
                    // https://stackoverflow.com/questions/492799/difference-between-invariantculture-and-ordinal-string-comparison
                    return(string.CompareOrdinal(name, candidate.LinkName));
                }
            });

            if (success)
            {
                if (candidate == null)
                {
                    throw new Exception("This should never happen. Just to satisfy the compiler.");
                }

                linkMessage = candidate;
                return(true);
            }

            return(false);
        }
예제 #2
0
        private IEnumerable <LinkMessage> EnumerateLinkMessagesFromLinkInfoMessage(LinkInfoMessage infoMessage)
        {
            var fractalHeap     = infoMessage.FractalHeap;
            var btree2NameIndex = infoMessage.BTree2NameIndex;
            var records         = btree2NameIndex
                                  .EnumerateRecords()
                                  .ToList();

            // local cache: indirectly accessed, non-filtered
            List <BTree2Record01>?record01Cache = null;

            foreach (var record in records)
            {
                using var localReader = new H5BinaryReader(new MemoryStream(record.HeapId));
                var heapId = FractalHeapId.Construct(this.Context, localReader, fractalHeap);

                yield return(heapId.Read(reader =>
                {
                    var message = new LinkMessage(reader, this.Context.Superblock);
                    return message;
                }, ref record01Cache));
            }
        }