Пример #1
0
        public Task <SCG.IReadOnlyDictionary <K, Entry <K, V> > > GetManyAsync(IReadOnlySet <K> keys)
        {
            return(ExecCommandAsync(async cmd => {
                // Retrieve all rows
                cmd.CommandText = $"SELECT * FROM {tableName} WHERE id=ANY(@ids)";
                var idParameter = cmd.CreateParameter();
                idParameter.ParameterName = "ids";
                idParameter.Value = keys.ToArray();
                cmd.Parameters.Add(idParameter);

                using (var reader = await cmd.ExecuteReaderAsync().ConfigureAwait(false)) {
                    var results = new SCG.Dictionary <K, Entry <K, V> >();
                    while (await reader.ReadAsync().ConfigureAwait(false))
                    {
                        var entry = ReadToEntry(reader);
                        results[entry.Key] = entry;
                    }
                    foreach (var key in keys)
                    {
                        if (!results.ContainsKey(key))
                        {
                            results[key] = Entry <K, V> .CreateNonexistant(key);
                        }
                    }
                    return (SCG.IReadOnlyDictionary <K, Entry <K, V> >)results;
                }
            }));
        }
Пример #2
0
 public ProblemSolver(IEnumerable <int> input)
 {
     inputSet = input.ToHashSet();
     inputMem = inputSet.ToArray();
 }