@@ -16,6 +16,11 @@ public class StringTable(ReadOnlyMemory<OffsetAndSize> stringTable, ReadOnlyMemo
1616 readonly ReadOnlyMemory < OffsetAndSize > _stringTable = stringTable ;
1717 readonly ReadOnlyMemory < byte > _stringData = stringData ;
1818
19+ /// <summary>
20+ /// Creates a string table from bytes
21+ /// </summary>
22+ /// <param name="data"></param>
23+ /// <returns></returns>
1924 public static StringTable Create ( ReadOnlyMemory < byte > data )
2025 {
2126 var blocks = data . GetTupleFromBlockHeader < OffsetAndSize , byte > ( ) ;
@@ -25,6 +30,11 @@ public static StringTable Create(ReadOnlyMemory<byte> data)
2530 ) ;
2631 }
2732
33+ /// <summary>
34+ /// Creates a string table from a file
35+ /// </summary>
36+ /// <param name="filePath"></param>
37+ /// <returns></returns>
2838 public static async Task < StringTable > Create ( string filePath )
2939 {
3040 return Create ( await File . ReadAllBytesAsync ( filePath ) ) ;
@@ -65,13 +75,15 @@ public string[] GetAll(int maxStringSize = 1024)
6575 /// <returns></returns>
6676 /// <exception cref="Exception"></exception>
6777 /// <exception cref="NotImplementedException"></exception>
68- public async Task < IIndexStrings > GetStringIndexer ( StringIndexType type = StringIndexType . Dictionary , int maxStringSize = 1024 )
78+ public Task < IIndexStrings > GetStringIndexer ( StringIndexType type = StringIndexType . Dictionary , int maxStringSize = 1024 )
6979 {
7080 var span = _stringTable . Span ;
7181 var dataSpan = _stringData . Span ;
82+ IIndexStrings ret ;
7283 switch ( type ) {
7384 case StringIndexType . Dictionary : {
74- return new FrozenDictionaryStringIndexer ( span , dataSpan , maxStringSize ) ;
85+ ret = new FrozenDictionaryStringIndexer ( span , dataSpan , maxStringSize ) ;
86+ break ;
7587 }
7688 case StringIndexType . Trie : {
7789 using var buffer = SpanOwner < char > . Allocate ( maxStringSize ) ;
@@ -82,11 +94,14 @@ public async Task<IIndexStrings> GetStringIndexer(StringIndexType type = StringI
8294 var bufferSize = Encoding . UTF8 . GetChars ( utf8 , bufferSpan ) ;
8395 trieBuilder . Add ( bufferSpan [ ..bufferSize ] , i ) ;
8496 }
85- return new TrieStringIndexer ( trieBuilder . Build ( ) , this ) ;
97+ ret = new TrieStringIndexer ( trieBuilder . Build ( ) , this ) ;
98+ break ;
8699 }
87100 default :
88101 throw new NotImplementedException ( type . ToString ( ) ) ;
89102 }
103+
104+ return Task . FromResult ( ret ) ;
90105 }
91106
92107 /// <summary>
@@ -95,7 +110,7 @@ public async Task<IIndexStrings> GetStringIndexer(StringIndexType type = StringI
95110 /// <param name="tokenizer"></param>
96111 /// <param name="maxStringSize"></param>
97112 /// <returns></returns>
98- public async Task < IIndexStrings > GetStringIndexer ( Func < ReadOnlySpan < char > , ReadOnlySpan < int > > tokenizer , int maxStringSize = 1024 )
113+ public Task < IIndexStrings > GetStringIndexer ( Func < ReadOnlySpan < char > , ReadOnlySpan < int > > tokenizer , int maxStringSize = 1024 )
99114 {
100115 // build the tokenized trie
101116 using var buffer = SpanOwner < char > . Allocate ( maxStringSize ) ;
@@ -109,7 +124,8 @@ public async Task<IIndexStrings> GetStringIndexer(Func<ReadOnlySpan<char>, ReadO
109124 trieBuilder . Add ( tokenizer ( bufferSpan [ ..bufferSize ] ) , i ) ;
110125 }
111126
112- return new TokenizedTrieStringIndexer ( trieBuilder . Build ( ) , this , tokenizer ) ;
127+ IIndexStrings ret = new TokenizedTrieStringIndexer ( trieBuilder . Build ( ) , this , tokenizer ) ;
128+ return Task . FromResult ( ret ) ;
113129 }
114130 }
115131}
0 commit comments