Beispiel #1
0
        void readNodes(BinaryReader input, GeneralGraph graph)
        {
            uint _uid;
            uint _typeOfNode;

            do
            {
                _uid        = input.ReadUInt32( );
                _typeOfNode = input.ReadUInt32( );
                if (_uid == 0 &&
                    _typeOfNode == 0)
                {
                    break;
                }

                Node _source           = getOrCreateNode(graph, _uid);
                var  _attributesOfNode = readAttributes(input);
                _source.AddAttributes(_attributesOfNode.ToArray( ));
                _source.Type           = texts[_typeOfNode];
                _source.TimeOfCreation = DateTime.Now;

                readEdges(input, graph, _source);

                graph.Add(_source);
            } while (_uid != 0 &&
                     _typeOfNode != 0);
        }
Beispiel #2
0
        void readMetaData(BinaryReader _input, GeneralGraph _graph)
        {
            uint _numberOfHeaders = _input.ReadUInt32( );

            for (int _i = 0; _i < _numberOfHeaders; _i++)
            {
                uint _key   = _input.ReadUInt32( );
                uint _value = _input.ReadUInt32( );
                _graph.AddMetaData(texts[_key], texts[_value]);
            }
        }
Beispiel #3
0
        GeneralGraph Load(Stream input, string name)
        {
            GeneralGraph _graph = new GeneralGraph(name);

            using (BinaryReader _input = new BinaryReader(input))
            {
                checkMagicNumber(_input);
                skipBuckets(_input);
                readTexts(_input);
                readMetaData(_input, _graph);
                readNodes(_input, _graph);
            }
            return(_graph);
        }
Beispiel #4
0
            void TestLoader( )
            {
                Loader        _loader  = new Loader( );
                DirectoryInfo _samples = new DirectoryInfo("samples");

                if (_samples.Exists)
                {
                    foreach (var _file in _samples.GetFiles("*.graph"))
                    {
                        GeneralGraph _graph = _loader.Load(_file);
                        _graph.DumpToFile( );
                        Process.Start(
                            new ProcessStartInfo(@"native-dumper\GraphDump.exe", "-xml " + _file.FullName));
                    }
                }
            }
Beispiel #5
0
        Node getOrCreateNode(GeneralGraph graph, uint uid)
        {
            Node _node;
            var  _id             = texts[uid];
            var  _nodeCandidates = graph.Nodes.Where(_n => _n.UniqueID == _id);
            var  _candidates     = _nodeCandidates as Node[] ?? _nodeCandidates.ToArray( );

            if (_candidates.Any( ))
            {
                _node = _candidates.First( );
            }
            else
            {
                _node = new Node(_id, string.Empty);
            }
            return(_node);
        }
Beispiel #6
0
        void readEdges(BinaryReader _input, GeneralGraph _graph, Node _source)
        {
            uint _typeKey;
            uint _directionOfEdge;
            uint _targetKey;

            do
            {
                _typeKey         = _input.ReadUInt32( );
                _directionOfEdge = _input.ReadUInt32( );
                _targetKey       = _input.ReadUInt32( );
                if (_typeKey == 0 && _directionOfEdge == 0 &&
                    _targetKey == 0)
                {
                    break;
                }
                string _typeOfEdge       = texts[_typeKey];
                bool   _pairNeeded       = _input.ReadBoolean( );
                var    _attributesOfEdge = readAttributes(_input);
                Node   _target           = getOrCreateNode(_graph, _targetKey);

                switch (_directionOfEdge)
                {
                case 0:
                    var _undirectedEdge = _graph.Connect(_source, _typeOfEdge, _target);
                    _undirectedEdge.Attributes.AddAttributes(_attributesOfEdge.ToArray( ));
                    break;

                case 1:
                    var _directedEdge = _graph.ConnectDirected(_source, _typeOfEdge, _target);
                    _directedEdge.ForwardAttributes.AddAttributes(_attributesOfEdge.ToArray( ));
                    if (_pairNeeded)
                    {
                        var _attributesOfReverseEdge = readAttributes(_input);
                        _directedEdge.BackwardAttributes.AddAttributes(_attributesOfReverseEdge.ToArray( ));
                    }
                    break;

                default:
                    throw new NotSupportedException("unknown edge direction");
                }
            } while (_typeKey != 0 && _directionOfEdge != 0 &&
                     _targetKey != 0);
        }
Beispiel #7
0
 GeneralGraphWalker(GeneralGraph graph)
 {
     this.graph = graph;
 }