public unsafe ICellAccessor UseGenericCell(Trinity.Storage.LocalMemoryStorage storage, long CellId) { ushort type; int size; byte * cellPtr; int entryIndex; var err = storage.GetLockedCellInfo(CellId, out size, out type, out cellPtr, out entryIndex); if (err != TrinityErrorCode.E_SUCCESS) { throw new CellNotFoundException("Cannot access the cell."); } switch ((CellType)type) { case CellType.Movie: return(Movie_Accessor.New(CellId, cellPtr, entryIndex, CellAccessOptions.ThrowExceptionOnCellNotFound)); case CellType.Celebrity: return(Celebrity_Accessor.New(CellId, cellPtr, entryIndex, CellAccessOptions.ThrowExceptionOnCellNotFound)); default: storage.ReleaseCellLock(CellId, entryIndex); throw new CellTypeNotMatchException("Cannot determine cell type."); } }
/// <inheritdoc/> public unsafe ICell LoadGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId) { ushort type; int size; byte * cellPtr; int entryIndex; var err = storage.GetLockedCellInfo(cellId, out size, out type, out cellPtr, out entryIndex); if (err != TrinityErrorCode.E_SUCCESS) { throw new CellNotFoundException("Cannot access the cell."); } try { var accessor = UseGenericCell(cellId, cellPtr, entryIndex, type); var cell = accessor.Deserialize(); accessor.Dispose(); return(cell); } catch (Exception ex) { storage.ReleaseCellLock(cellId, entryIndex); ExceptionDispatchInfo.Capture(ex).Throw(); throw; } }
public unsafe ICell LoadGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId) { ushort type; int size; byte * cellPtr; int entryIndex; var err = storage.GetLockedCellInfo(cellId, out size, out type, out cellPtr, out entryIndex); if (err != TrinityErrorCode.E_SUCCESS) { throw new CellNotFoundException("Cannot access the cell."); } switch ((CellType)type) { /*FOREACH*/ case CellType.t_cell_name: var t_cell_name_accessor = new t_cell_name_Accessor(cellPtr); var t_cell_name_cell = (t_cell_name)t_cell_name_accessor; storage.ReleaseCellLock(cellId, entryIndex); t_cell_name_cell.CellID = cellId; return(t_cell_name_cell); break; /*END*/ default: throw new CellTypeNotMatchException("Cannot determine cell type."); } }
/// <inheritdoc/> public unsafe ICellAccessor UseGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId) { ushort type; int size; byte * cellPtr; int entryIndex; var err = storage.GetLockedCellInfo(cellId, out size, out type, out cellPtr, out entryIndex); if (err != TrinityErrorCode.E_SUCCESS) { throw new CellNotFoundException("Cannot access the cell."); } switch ((CellType)type) { /*FOREACH*/ case CellType.t_cell_name: return(t_cell_name_Accessor._get()._Setup(cellId, cellPtr, entryIndex, CellAccessOptions.ThrowExceptionOnCellNotFound)); /*END*/ default: storage.ReleaseCellLock(cellId, entryIndex); throw new CellTypeNotMatchException("Cannot determine cell type."); } }
public unsafe static node Loadnode(this Trinity.Storage.LocalMemoryStorage storage, long CellID) { using (var cell = new node_Accessor(CellID, ActionOnCellNotFound.ThrowException)) { node ret = cell; ret.CellID = CellID; return(ret); } }
/// <inheritdoc/> public void SaveGenericCell(Trinity.Storage.LocalMemoryStorage storage, CellAccessOptions writeAheadLogOptions, long cellId, ICell cell) { switch ((CellType)cell.CellType) { case CellType.TripleStore: storage.SaveTripleStore(writeAheadLogOptions, cellId, (TripleStore)cell); break; } }
public unsafe static SSSPCell LoadSSSPCell(this Trinity.Storage.LocalMemoryStorage storage, long CellID) { using (var cell = new SSSPCell_Accessor(CellID, ActionOnCellNotFound.ThrowException)) { SSSPCell ret = cell; ret.CellID = CellID; return(ret); } }
/// <inheritdoc/> public void SaveGenericCell(Trinity.Storage.LocalMemoryStorage storage, CellAccessOptions writeAheadLogOptions, ICell cell) { switch ((CellType)cell.CellType) { case CellType.Graph: storage.SaveGraph(writeAheadLogOptions, (Graph)cell); break; } }
public void SaveGenericCell(Trinity.Storage.LocalMemoryStorage storage, CellAccessOptions writeAheadLogOptions, long cellId, ICell cell) { switch ((CellType)cell.CellType) { /*FOREACH*/ case CellType.t_cell_name: storage.Savet_cell_name(writeAheadLogOptions, cellId, (t_cell_name)cell); break; /*END*/ } }
public void SaveGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId, ICell cell) { switch ((CellType)cell.CellType) { /*FOREACH*/ case CellType.t_cell_name: storage.Savet_cell_name(cellId, (t_cell_name)cell); break; /*END*/ } }
/// <inheritdoc/> public unsafe ICellAccessor UseGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId, CellAccessOptions options, string cellType) { switch (cellType) { case "TripleStore": return(TripleStore_Accessor._get()._Lock(cellId, options)); default: Throw.invalid_cell_type(); return(null); } }
public unsafe static bool IsSSSPCell(this Trinity.Storage.LocalMemoryStorage storage, long CellID) { //int idx; //int size; //byte* ptr = storage.GetLockedUnsafeCellLocation(CellID, out size, out idx); //if (ptr == null) // throw new Exception(string.Format("Cell #{0} doesn't exist.", CellID)); //bool ret = *ptr == (byte)CellType.SSSPCell; //storage.ReleaseCellLock(CellID, idx); //return ret; return(storage.GetCellType(CellID) == (ushort)CellType.SSSPCell); }
public unsafe static CellType GetCellType(this Trinity.Storage.LocalMemoryStorage storage, long CellID) { //int idx; //int size; //byte* ptr = storage.GetLockedUnsafeCellLocation(CellID, out size, out idx); //if (ptr == null) // throw new Exception(string.Format("Cell #{0} doesn't exist.", CellID)); //CellType ret = (CellType)(*ptr); //storage.ReleaseCellLock(CellID, idx); //return ret; return((CellType)storage.GetCellType(CellID)); }
/// <summary> /// Allocate a generic cell accessor on the specified cell. /// If <c><see cref="Trinity.TrinityConfig.ReadOnly"/> == false</c>, /// on calling this method, it attempts to acquire the lock of the cell, /// and blocks until it gets the lock. /// </summary> /// <param name="storage">A <see cref="Trinity.Storage.LocalMemoryStorage"/> instance.</param> /// <param name="CellId">The id of the specified cell.</param> /// <param name="options">Specifies write-ahead logging behavior. Valid values are CellAccessOptions.StrongLogAhead(default) and CellAccessOptions.WeakLogAhead. Other values are ignored.</param> /// <returns>A <see cref="t_Namespace.GenericCellAccessor"/> instance.</returns> public unsafe ICellAccessor UseGenericCell(Trinity.Storage.LocalMemoryStorage storage, long CellId, CellAccessOptions options) { ushort type; int size; byte * cellPtr; int entryIndex; var err = storage.GetLockedCellInfo(CellId, out size, out type, out cellPtr, out entryIndex); switch (err) { case TrinityErrorCode.E_SUCCESS: break; case TrinityErrorCode.E_CELL_NOT_FOUND: { if ((options & CellAccessOptions.ThrowExceptionOnCellNotFound) != 0) { Throw.cell_not_found(CellId); } else if ((options & CellAccessOptions.CreateNewOnCellNotFound) != 0) { throw new ArgumentException("CellAccessOptions.CreateNewOnCellNotFound is not valid for this method. Cannot determine new cell type.", "options"); } else if ((options & CellAccessOptions.ReturnNullOnCellNotFound) != 0) { return(null); } else { Throw.cell_not_found(CellId); } break; } default: throw new CellNotFoundException("Cannot access the cell."); } switch ((CellType)type) { /*FOREACH*/ case CellType.t_cell_name: return(t_cell_name_Accessor.New(CellId, cellPtr, entryIndex, options)); /*END*/ default: storage.ReleaseCellLock(CellId, entryIndex); throw new CellTypeNotMatchException("Cannot determine cell type."); } ; }
public void SaveGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId, ICell cell) { switch ((CellType)cell.CellType) { case CellType.Movie: storage.SaveMovie(cellId, (Movie)cell); break; case CellType.Celebrity: storage.SaveCelebrity(cellId, (Celebrity)cell); break; } }
/// <summary> /// Allocate a generic cell accessor on the specified cell. /// If <c><see cref="Trinity.TrinityConfig.ReadOnly"/> == false</c>, /// on calling this method, it attempts to acquire the lock of the cell, /// and blocks until it gets the lock. /// </summary> /// <param name="storage">A <see cref="Trinity.Storage.LocalMemoryStorage"/> instance.</param> /// <param name="CellId">The id of the specified cell.</param> /// <param name="options">Cell access options.</param> /// <param name="cellType">Specifies the type of cell to be created.</param> /// <returns>A <see cref="t_Namespace.GenericCellAccessor"/> instance.</returns> public unsafe ICellAccessor UseGenericCell(Trinity.Storage.LocalMemoryStorage storage, long CellId, CellAccessOptions options, string cellType) { switch (cellType) { /*FOREACH*/ case "t_cell_name": return(t_cell_name_Accessor.New(CellId, options)); /*END*/ default: Throw.invalid_cell_type(); return(null); // should not reach here } }
public void SaveGenericCell(Trinity.Storage.LocalMemoryStorage storage, CellAccessOptions writeAheadLogOptions, long cellId, ICell cell) { switch ((CellType)cell.CellType) { case CellType.Movie: storage.SaveMovie(writeAheadLogOptions, cellId, (Movie)cell); break; case CellType.Celebrity: storage.SaveCelebrity(writeAheadLogOptions, cellId, (Celebrity)cell); break; } }
/// <inheritdoc/> public unsafe ICellAccessor UseGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId, CellAccessOptions options) { ushort type; int size; byte * cellPtr; int entryIndex; var err = storage.GetLockedCellInfo(cellId, out size, out type, out cellPtr, out entryIndex); switch (err) { case TrinityErrorCode.E_SUCCESS: break; case TrinityErrorCode.E_CELL_NOT_FOUND: { if ((options & CellAccessOptions.ThrowExceptionOnCellNotFound) != 0) { Throw.cell_not_found(cellId); } else if ((options & CellAccessOptions.CreateNewOnCellNotFound) != 0) { throw new ArgumentException("CellAccessOptions.CreateNewOnCellNotFound is not valid for this method. Cannot determine new cell type.", "options"); } else if ((options & CellAccessOptions.ReturnNullOnCellNotFound) != 0) { return(null); } else { Throw.cell_not_found(cellId); } break; } default: throw new CellNotFoundException("Cannot access the cell."); } try { return(UseGenericCell(cellId, cellPtr, entryIndex, type, options)); } catch (Exception ex) { storage.ReleaseCellLock(cellId, entryIndex); ExceptionDispatchInfo.Capture(ex).Throw(); // should never reach here throw; } }
/// <summary> /// Perform actions to each corresponding cell in Trinity local storage. /// </summary> /// <param name="dispose">true indicates that current memory trunk will be disposed once it is processed; otherwise, the memory is kept in-memory.</param> /// <param name="parallel">true indicates the actions are performed in parallel; otherwise, the actions are performed sequentially.</param> /// <param name="actions">A list of CellAccessorActions.</param> public static unsafe void ForEach(this Trinity.Storage.LocalMemoryStorage storage, bool dispose, bool parallel, params CellAccessorAction[] actions) { Dictionary <ushort, Action <long, long, int> > actionMap = new Dictionary <ushort, Action <long, long, int> >(); foreach (var action in actions) { actionMap[(ushort)action.CellType] = action._action; } if (parallel) { Parallel.ForEach <MemoryTrunk>(storage.memory_trunks, mem_trunk => { mem_trunk.ForEach( new CellAction <long, int, int, ushort>( (byte *ptr, long id, int size, int idx, ushort cellType) => { if (actionMap.ContainsKey(cellType)) { actionMap[cellType](id, (long)ptr, idx); } })); if (dispose) { mem_trunk.Save(); mem_trunk.Dispose(); } }); } else { for (int i = 0; i < storage.memory_trunks.Length; i++) { storage.memory_trunks[i].ForEach( new CellAction <long, int, int, ushort>( (byte *ptr, long id, int size, int idx, ushort cellType) => { if (actionMap.ContainsKey(cellType)) { actionMap[cellType](id, (long)ptr, idx); } })); if (dispose) { storage.memory_trunks[i].Save(); storage.memory_trunks[i].Dispose(); } } } }
public unsafe static bool SaveSSSPCell(this Trinity.Storage.LocalMemoryStorage storage, long CellID, int distance = default(int), long parent = default(long), List <long> neighbors = null) { byte *targetPtr = null; targetPtr += 4; targetPtr += 8; if (neighbors != null) { targetPtr += neighbors.Count * 8 + sizeof(int); } else { targetPtr += sizeof(int); } byte[] tmpcell = new byte[(int)(targetPtr)]; fixed(byte *tmpcellptr = tmpcell) { targetPtr = tmpcellptr; *(int *)targetPtr = distance; targetPtr += 4; *(long *)targetPtr = parent; targetPtr += 8; if (neighbors != null) { *(int *)targetPtr = neighbors.Count * 8; targetPtr += sizeof(int); for (int iterator_0 = 0; iterator_0 < neighbors.Count; ++iterator_0) { *(long *)targetPtr = neighbors[iterator_0]; targetPtr += 8; } } else { *(int *)targetPtr = 0; targetPtr += sizeof(int); } } return(storage.SaveCell(CellID, tmpcell, (ushort)CellType.SSSPCell)); }
/// <summary> /// Perform actions to each corresponding cell in Trinity local storage. /// </summary> /// <param name="parallel">true indicates the actions are performed in parallel; otherwise, the actions are performed sequentially.</param> /// <param name="actions">A list of CellAccessorActions.</param> public static unsafe void ForEach(this Trinity.Storage.LocalMemoryStorage storage, bool parallel, params CellAccessorAction[] actions) { Dictionary <ushort, Action <long, long, int> > actionMap = new Dictionary <ushort, Action <long, long, int> >(); foreach (var action in actions) { actionMap[(ushort)action.CellType] = action._action; } storage.ForEach( new CellAction <long, int, int, ushort>( (byte *ptr, long id, int size, int idx, ushort cellType) => { if (actionMap.ContainsKey(cellType)) { actionMap[cellType](id, (long)ptr, idx); } }), parallel); }
public unsafe static void Transform(this Trinity.Storage.LocalMemoryStorage storage, params CellConverter[] converters) { Dictionary <ushort, CellTransformAction <long, int, ushort> > converterMap = new Dictionary <ushort, CellTransformAction <long, int, ushort> >(); foreach (var converter in converters) { converterMap[(ushort)converter.SourceCellType] = converter._action; } storage.TransformCells((byte *ptr, long id, int count, ref ushort cellType) => { //ushort cellType = *(ushort*)ptr; if (converterMap.ContainsKey(cellType)) { return(converterMap[cellType](ptr, id, count, ref cellType)); } else { byte[] ret = new byte[count]; Memory.Copy(ptr, 0, ret, 0, count); return(ret); } }); }
public unsafe ICell LoadGenericCell(Trinity.Storage.LocalMemoryStorage storage, long cellId) { ushort type; int size; byte * cellPtr; int entryIndex; var err = storage.GetLockedCellInfo(cellId, out size, out type, out cellPtr, out entryIndex); if (err != TrinityErrorCode.E_SUCCESS) { throw new CellNotFoundException("Cannot access the cell."); } switch ((CellType)type) { case CellType.Movie: var Movie_accessor = new Movie_Accessor(cellPtr); var Movie_cell = (Movie)Movie_accessor; storage.ReleaseCellLock(cellId, entryIndex); Movie_cell.CellID = cellId; return(Movie_cell); break; case CellType.Celebrity: var Celebrity_accessor = new Celebrity_Accessor(cellPtr); var Celebrity_cell = (Celebrity)Celebrity_accessor; storage.ReleaseCellLock(cellId, entryIndex); Celebrity_cell.CellID = cellId; return(Celebrity_cell); break; default: throw new CellTypeNotMatchException("Cannot determine cell type."); } }
public unsafe static SSSPCell_Accessor UseSSSPCell(this Trinity.Storage.LocalMemoryStorage storage, long CellID, ActionOnCellNotFound action) { return(SSSPCell_Accessor.New(CellID, action)); }
public unsafe static bool SaveSSSPCell(this Trinity.Storage.LocalMemoryStorage storage, SSSPCell CellContent) { return(SaveSSSPCell(storage, CellContent.CellID, CellContent.distance, CellContent.parent, CellContent.neighbors)); }
public IEnumerable <ICell> EnumerateGenericCells(LocalMemoryStorage storage) { throw new NotImplementedException(); }
public void SaveGenericCell(LocalMemoryStorage storage, CellAccessOptions writeAheadLogOptions, long cellId, ICell cell) { throw new NotImplementedException(); }
public static Type[] GetCellStructureTypeArray(this Trinity.Storage.LocalMemoryStorage storage) { return(new Type[] { typeof(StorageExtension_SSSPCell), }); }
public ICellAccessor UseGenericCell(LocalMemoryStorage storage, long cellId) { throw new NotImplementedException(); }
public ICellAccessor UseGenericCell(LocalMemoryStorage storage, long cellId, CellAccessOptions options, string cellType) { throw new NotImplementedException(); }