public double GetEdgeWeight(Guid guid, int eid) { int pageIndex = NetworkObjectSerializer.Page(eid); IWeightPage page = LoadWeightPage(guid, pageIndex); if (page == null) { return(0.0); } // Page 0: Edge 1...512: weightIndex: 0..511 auf Page 1 // Page 1: Edge 512..1024: weightIndex: 0..511 auf Page 2 // ... .... // Beispiele: // 0-> weightIndex=( 1-1)-0*512=0 // 512-> weightIndex=( 512-1)-0*512=511 // 513-> weightIndex=( 513-1)-1*512=0 // 1024-> weightIndex=(1024-1)-1*512=511 // ... int weightIndex = (eid - 1) - pageIndex * NetworkObjectSerializer.PageSize; return(page.GetWeight(weightIndex)); }
private IWeightPage LoadWeightPage(Guid guid, int page) { lock (_thisLock) { if (!_weightPagesDict.ContainsKey(guid)) { _weightPagesDict.Add(guid, new Dictionary <int, IWeightPage>()); } Dictionary <int, IWeightPage> weightPages = _weightPagesDict[guid]; if (weightPages.ContainsKey(page)) { return(weightPages[page]); } if (!_weightDataTypes.ContainsKey(guid) || !_weightTableNames.ContainsKey(guid)) { return(null); } if (_dbfactory != null) { try { using (DbConnection connection = _dbfactory.CreateConnection()) { connection.ConnectionString = _connectionString; DbCommand command = _dbfactory.CreateCommand(); command.Connection = connection; command.CommandText = "SELECT " + _dbNames.DbColName("Data") + " FROM " + _weightTableNames[guid] + " WHERE " + _dbNames.DbColName("Page") + "=" + page; connection.Open(); DbDataReader reader = command.ExecuteReader(); if (reader.Read()) { object obj = reader.GetValue(0); connection.Close(); IWeightPage weightPage = null; switch (_weightDataTypes[guid]) { case GraphWeightDataType.Double: weightPage = new DoubleWeightPage(); ((DoubleWeightPage)weightPage).Deserialize((byte[])obj); break; case GraphWeightDataType.Integer: weightPage = new IntWeightPage(); ((IntWeightPage)weightPage).Deserialize((byte[])obj); break; } return(weightPage); } connection.Close(); } } catch { } } return(null); } }