Whitespace changes
This commit is contained in:
parent
3b71cc49e6
commit
e7f284052e
104
db/DB.cs
104
db/DB.cs
@ -1,16 +1,16 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using Optional;
|
using Optional;
|
||||||
using static Optional.OptionExtensions;
|
using static Optional.OptionExtensions;
|
||||||
using static System.Collections.Immutable.ImmutableInterlocked;
|
using static System.Collections.Immutable.ImmutableInterlocked;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
???? Should we have an explicit transaction class/ID?
|
???? Should we have an explicit transaction class/ID?
|
||||||
???? Should we split things into threaded vs action
|
???? Should we split things into threaded vs action
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace db
|
namespace db
|
||||||
{
|
{
|
||||||
|
|
||||||
public enum CommitResults
|
public enum CommitResults
|
||||||
{
|
{
|
||||||
@ -24,9 +24,9 @@ namespace db
|
|||||||
TS id { get; }
|
TS id { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DB<TID, T> where T : IID<TID>
|
public class DB<TID, T> where T : IID<TID>
|
||||||
{
|
{
|
||||||
//Current snapshot of the DB.
|
//Current snapshot of the DB.
|
||||||
ImmutableDictionary<TID, T> m_objs = ImmutableDictionary<TID, T>.Empty;
|
ImmutableDictionary<TID, T> m_objs = ImmutableDictionary<TID, T>.Empty;
|
||||||
|
|
||||||
//List of committed Ids based on when they were committed.
|
//List of committed Ids based on when they were committed.
|
||||||
@ -35,23 +35,23 @@ namespace db
|
|||||||
ImmutableDictionary<TID, T> Objects => m_objs;
|
ImmutableDictionary<TID, T> Objects => m_objs;
|
||||||
|
|
||||||
// @@@@ TODO This returns an entity that can be changing. It should be a lazy instantiated copy
|
// @@@@ TODO This returns an entity that can be changing. It should be a lazy instantiated copy
|
||||||
public Option<T> lookup( TID id )
|
public Option<T> lookup( TID id )
|
||||||
{
|
{
|
||||||
if( m_objs.TryGetValue( id, out T obj ) )
|
if( m_objs.TryGetValue( id, out T obj ) )
|
||||||
{
|
{
|
||||||
return obj.Some();
|
return obj.Some();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// LOG
|
// LOG
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj.None();
|
return obj.None();
|
||||||
}
|
}
|
||||||
|
|
||||||
public (Tx<TID, T>, Option<T>) checkout( TID id )
|
public (Tx<TID, T>, Option<T>) checkout( TID id )
|
||||||
{
|
{
|
||||||
var tx = new Tx<TID, T>( m_committed.Count, m_activeTransaction, this );
|
var tx = new Tx<TID, T>( m_committed.Count, m_activeTransaction, this );
|
||||||
|
|
||||||
var v = lookup( id );
|
var v = lookup( id );
|
||||||
|
|
||||||
@ -59,27 +59,27 @@ namespace db
|
|||||||
tx.checkout( id );
|
tx.checkout( id );
|
||||||
}, () => {
|
}, () => {
|
||||||
} );
|
} );
|
||||||
|
|
||||||
return (tx, v);
|
return (tx, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tx<TID, T> checkout( TID id, out Option<T> tOut )
|
public Tx<TID, T> checkout( TID id, out Option<T> tOut )
|
||||||
{
|
{
|
||||||
var (tx, v) = checkout(id);
|
var (tx, v) = checkout(id);
|
||||||
|
|
||||||
tOut = v;
|
tOut = v;
|
||||||
|
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tx<TID, T> checkout()
|
public Tx<TID, T> checkout()
|
||||||
{
|
{
|
||||||
var tx = new Tx<TID, T>( m_committed.Count, m_activeTransaction, this );
|
var tx = new Tx<TID, T>( m_committed.Count, m_activeTransaction, this );
|
||||||
|
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommitResults commit( ref Tx<TID, T> co )
|
public CommitResults commit( ref Tx<TID, T> co )
|
||||||
{
|
{
|
||||||
co = null;
|
co = null;
|
||||||
return commit_internal_single( co );
|
return commit_internal_single( co );
|
||||||
@ -92,7 +92,7 @@ namespace db
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal CommitResults commit_internal_single( Tx<TID, T> tx )
|
internal CommitResults commit_internal_single( Tx<TID, T> tx )
|
||||||
{
|
{
|
||||||
//var collision = false;
|
//var collision = false;
|
||||||
|
|
||||||
@ -140,8 +140,8 @@ namespace db
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Option<Tx<TID, T>> m_activeTransaction = Option.None<Tx<TID, T>>();
|
Option<Tx<TID, T>> m_activeTransaction = Option.None<Tx<TID, T>>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum TxStates
|
public enum TxStates
|
||||||
@ -153,9 +153,9 @@ namespace db
|
|||||||
|
|
||||||
|
|
||||||
//This only works for a single thread
|
//This only works for a single thread
|
||||||
public class Tx<TID, T>: IDisposable where T : IID<TID>
|
public class Tx<TID, T>: IDisposable where T : IID<TID>
|
||||||
{
|
{
|
||||||
internal ImmutableList<T> Checkouts => m_checkouts;
|
internal ImmutableList<T> Checkouts => m_checkouts;
|
||||||
internal TxStates State => m_state;
|
internal TxStates State => m_state;
|
||||||
internal int Start => m_start;
|
internal int Start => m_start;
|
||||||
internal ImmutableList<T> Adds => m_adds;
|
internal ImmutableList<T> Adds => m_adds;
|
||||||
@ -191,33 +191,33 @@ namespace db
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Option<T> checkout( TID id )
|
public Option<T> checkout( TID id )
|
||||||
{
|
{
|
||||||
var v = m_db.lookup( id );
|
var v = m_db.lookup( id );
|
||||||
|
|
||||||
v.MatchSome( t => { m_checkouts = m_checkouts.Add( t ); } );
|
v.MatchSome( t => { m_checkouts = m_checkouts.Add( t ); } );
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add( T obj )
|
public void add( T obj )
|
||||||
{
|
{
|
||||||
m_adds = m_adds.Add(obj);
|
m_adds = m_adds.Add(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int m_start = -1;
|
int m_start = -1;
|
||||||
DB<TID, T> m_db;
|
DB<TID, T> m_db;
|
||||||
|
|
||||||
//Do we need these? Do we need both?
|
//Do we need these? Do we need both?
|
||||||
Option<Tx<TID, T>> m_parentTx;
|
Option<Tx<TID, T>> m_parentTx;
|
||||||
ImmutableList<Tx<TID, T>> m_childTx = ImmutableList<Tx<TID, T>>.Empty;
|
ImmutableList<Tx<TID, T>> m_childTx = ImmutableList<Tx<TID, T>>.Empty;
|
||||||
|
|
||||||
TxStates m_state = TxStates.Invalid;
|
TxStates m_state = TxStates.Invalid;
|
||||||
ImmutableList<T> m_checkouts = ImmutableList<T>.Empty;
|
ImmutableList<T> m_checkouts = ImmutableList<T>.Empty;
|
||||||
|
|
||||||
// New objects created this pass
|
// New objects created this pass
|
||||||
ImmutableList<T> m_adds = ImmutableList<T>.Empty;
|
ImmutableList<T> m_adds = ImmutableList<T>.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user