Skip to content

Commit

Permalink
Added file comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HermanSchoenfeld committed Jan 4, 2024
1 parent 46964ab commit 2124b3d
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 18 deletions.
11 changes: 1 addition & 10 deletions src/Hydrogen/Collections/StreamMapped/StreamMappedFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,7 @@ out KeyChecksumIndex<KeyValuePair<TKey, TValue>, TKey> keyChecksumKeyIndex
container.RegisterAttachment(recyclableIndexIndex);

// Create key checksum index (for fast key lookups)
keyChecksummer ??= new ItemDigestor<TKey>(keySerializer, container.StreamContainer.Endianness);
keyChecksumKeyIndex = new KeyChecksumIndex<KeyValuePair<TKey, TValue>, TKey>(
container,
keyChecksumIndexStreamIndex,
kvp => kvp.Key,
keyChecksummer,
ReadKey,
keyComparer
);
container.RegisterAttachment(keyChecksumKeyIndex);
keyChecksumKeyIndex = container.AddChecksumKeyIndex(kvp => kvp.Key, keyChecksummer, keySerializer, ReadKey, keyComparer, keyChecksumIndexStreamIndex);

return container;

Expand Down
10 changes: 9 additions & 1 deletion src/Hydrogen/ObjectSpaces/Attributes/UniquePropertyAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
using System;
// Copyright (c) Sphere 10 Software. All rights reserved. (https://sphere10.com)
// Author: Herman Schoenfeld
//
// Distributed under the MIT software license, see the accompanying file
// LICENSE or visit http://www.opensource.org/licenses/mit-license.php.
//
// This notice must not be removed when duplicating this file or its contents, in whole or in part.

using System;
using System.Collections.Generic;
using System.Text;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
namespace Hydrogen.ObjectSpaces;
// Copyright (c) Sphere 10 Software. All rights reserved. (https://sphere10.com)
// Author: Herman Schoenfeld
//
// Distributed under the MIT software license, see the accompanying file
// LICENSE or visit http://www.opensource.org/licenses/mit-license.php.
//
// This notice must not be removed when duplicating this file or its contents, in whole or in part.

namespace Hydrogen.ObjectSpaces;

public interface IObjectContainerAttachment {
ObjectContainer Container { get; }
Expand Down
1 change: 1 addition & 0 deletions src/Hydrogen/ObjectSpaces/Container/ObjectContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ internal T GetAttachment<T>(long reservedStream) where T : IObjectContainerAttac
return (T)_attachments[reservedStream];
}


#endregion

#region Event Notification
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
using System;
// Copyright (c) Sphere 10 Software. All rights reserved. (https://sphere10.com)
// Author: Herman Schoenfeld
//
// Distributed under the MIT software license, see the accompanying file
// LICENSE or visit http://www.opensource.org/licenses/mit-license.php.
//
// This notice must not be removed when duplicating this file or its contents, in whole or in part.

using System;
using System.IO;
using System.Runtime.CompilerServices;

Expand Down
20 changes: 20 additions & 0 deletions src/Hydrogen/ObjectSpaces/Container/ObjectContainerT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
// This notice must not be removed when duplicating this file or its contents, in whole or in part.


using System;
using System.Collections.Generic;
using static Hydrogen.AMS;

namespace Hydrogen.ObjectSpaces;

Expand Down Expand Up @@ -35,4 +37,22 @@ internal ClusteredStream SaveItemAndReturnStream(long index, T item, ObjectConta
item = (T)obj;
return result;
}

internal KeyChecksumIndex<T, TKey> AddChecksumKeyIndex<TKey>(Func<T, TKey> projection, long streamIndex, IItemSerializer<TKey> keySerializer = null, IItemChecksummer<TKey> keyChecksummer= null, Func<long, TKey> keyFetcher= null, IEqualityComparer<TKey> keyComparer= null) {
keyChecksummer ??= new ItemDigestor<TKey>(keySerializer, StreamContainer.Endianness);
keyFetcher ??= x => projection(LoadItem(x));
var keyChecksumKeyIndex = new KeyChecksumIndex<T, TKey>(
this,
streamIndex,
projection,
keyChecksummer,
keyFetcher,
keyComparer
);
RegisterAttachment(keyChecksumKeyIndex);

return keyChecksumKeyIndex;
}


}
10 changes: 9 additions & 1 deletion src/Hydrogen/ObjectSpaces/Definitions/ObjectSpaceDefinition.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
using System;
// Copyright (c) Sphere 10 Software. All rights reserved. (https://sphere10.com)
// Author: Herman Schoenfeld
//
// Distributed under the MIT software license, see the accompanying file
// LICENSE or visit http://www.opensource.org/licenses/mit-license.php.
//
// This notice must not be removed when duplicating this file or its contents, in whole or in part.

using System;
using Hydrogen.Mapping;

namespace Hydrogen.ObjectSpaces;
Expand Down
10 changes: 9 additions & 1 deletion src/Hydrogen/ObjectSpaces/Definitions/ObjectSpaceFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
namespace Hydrogen.ObjectSpaces;
// Copyright (c) Sphere 10 Software. All rights reserved. (https://sphere10.com)
// Author: Herman Schoenfeld
//
// Distributed under the MIT software license, see the accompanying file
// LICENSE or visit http://www.opensource.org/licenses/mit-license.php.
//
// This notice must not be removed when duplicating this file or its contents, in whole or in part.

namespace Hydrogen.ObjectSpaces;

public class ObjectSpaceFile {
public string FilePath { get; set; }
Expand Down
15 changes: 12 additions & 3 deletions src/Hydrogen/ObjectSpaces/ObjectSpace.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
using System;
// Copyright (c) Sphere 10 Software. All rights reserved. (https://sphere10.com)
// Author: Herman Schoenfeld
//
// Distributed under the MIT software license, see the accompanying file
// LICENSE or visit http://www.opensource.org/licenses/mit-license.php.
//
// This notice must not be removed when duplicating this file or its contents, in whole or in part.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
Expand Down Expand Up @@ -157,15 +165,16 @@ IObjectContainerAttachment BuildUniqueKey(ObjectContainer container, ObjectSpace
}

IObjectContainerAttachment BuildIndex(ObjectContainer container, ObjectSpaceDefinition.ContainerDefinition containerDefinition, ObjectSpaceDefinition.IndexDefinition indexDefinition, int streamIndex) {
var dataProviderType = typeof(KeyIndex<,>).MakeGenericType(containerDefinition.ObjectType, indexDefinition.KeyMember.PropertyType);
var dataProviderType = typeof(KeyChecksumIndex<,>).MakeGenericType(containerDefinition.ObjectType, indexDefinition.KeyMember.PropertyType);
//var projectionType = typeof(Func<,>).MakeGenericType(containerDefinition.ObjectType, indexDefinition.KeyMember.PropertyType);
var projection = Tools.Lambda.ConvertFunc(indexDefinition.KeyMember.GetValue, containerDefinition.ObjectType, indexDefinition.KeyMember.PropertyType);
var keyComparer = _comparerFactory.GetEqualityComparer(indexDefinition.KeyMember.PropertyType);
var serializer = _serializerFactory.GetSerializer(indexDefinition.KeyMember.PropertyType);

// public ObjectContainerUniqueKey(ObjectContainer container, long reservedStreamIndex, Func<TItem, TKey> projection, IEqualityComparer<TKey> keyComparer, IItemSerializer<TKey> keySerializer) {
try {
var uniqueKeyInstance = dataProviderType.ActivateWithCompatibleArgs(container, (long)streamIndex, projection, keyComparer, serializer);
//obj
var uniqueKeyInstance = dataProviderType.ActivateWithCompatibleArgs(container, (long)streamIndex, projection, null, null, keyComparer); // keyFetcher and keyChecksummer are null as method will auto-create
return (IObjectContainerAttachment)uniqueKeyInstance;
} catch (Exception ex) {
var xxx = ex.ToDiagnosticString();
Expand Down

0 comments on commit 2124b3d

Please sign in to comment.