- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经声明了一个类似于下面的类型。
type
TLikes = record
Name : string[20];
favColours : array of string[20];
faves = array of TLikes;
填充记录后,我将它们保存到二进制文件中,因此结构如下所示。
[John], [Green] [White] [Blue]
[Paul], [Blue] [Red] [White] [Green]
[David], [Red] [Blue] [Green]
[Bob], [White] [Blue]
[Peter], [Blue] [Green] [Red]
例如,很容易找出大卫喜欢什么颜色。当我想知道谁喜欢蓝色时出现了一个小问题。所以我所做的是构建第二个文件,就像这样……
[Blue], [John] [Paul] [David] [Peter] [Bob]
[Red], [David] [Paul] [Peter]
[White], [Bob] [David] [John] [Paul]
[Green], [John] [David] [Paul] [Peter]
但有些事情告诉我,我真的不需要创建第二个文件/数据结构,这看起来效率很低。
这是一个更大的问题......
如果我需要找到谁喜欢 David 喜欢的任何组合怎么办?我的结果是……
Blue and red and green = Paul, David, Peter
Blue and red = Paul, David, Peter
Blue and green = John, Paul, David, Peter
Red and Green = Paul, David, Peter
我的问题是。
是否有更好的方法来构建数据/记录,以便我可以找出 Bob 和 Paul 的共同点(蓝色和白色)或红色和白色的共同点(David 和 Paul)?
我想我需要指出,我已尝试简化上面的示例。实际上,Tlikes.Name 的数据将是类似...的字符串
‘decabbadc’
‘bacddbcad’
‘eebadeaac’
这些字符串中大约有 200k+ 个。 Tlikes.FavColours 数据是一个文件名(这些文件大约有 2k 个)。文件名表示包含 Tlikes.Name 字符串的文件。
我希望能够检索给定 Tlikes.Name 字符串的文件名列表或给定文件名的字符串列表。
注意——有些东西吸引我去“集合”,但据我所知,集合中的元素数量有限,我走的路对吗?
感谢您花时间阅读这篇文章。
最佳答案
这是一个通用集,TSet<T>
它可以用作获取数据之间关系的工具。
TSet<T>
可以保存简单类型的数据,不像普通的那样限制字节大小 Set
类型。
支持:
使用 TSet<T>
对您的应用程序进行基准测试。
unit GenericSet;
interface
Uses
System.Generics.Defaults,
System.Generics.Collections;
Type
TSet<T> = record
// Include (union)
class operator Add(const aSet: TSet<T>; aValue: T) : TSet<T>; overload;
class operator Add(const aSet: TSet<T>; const aTArr: TArray<T>) : TSet<T>; overload;
class operator Add(const aSet1: TSet<T>; const aSet2: TSet<T>) : TSet<T>; overload;
// Exclude
class operator Subtract(const aSet: TSet<T>; aValue: T): TSet<T>; overload;
class operator Subtract(const aSet: TSet<T>; const aTArr: TArray<T>) : TSet<T>; overload;
class operator Subtract(const aSet1: TSet<T>; const aSet2: TSet<T>) : TSet<T>; overload;
// left in right, i.e right.Contains(left)
class operator In(aValue: T; const aSet: TSet<T>): Boolean; overload;
class operator In(const aTArr: TArray<T>; const aSet: TSet<T>): Boolean; overload;
class operator In(const aSet1: TSet<T>; const aSet2: TSet<T>): Boolean; overload;
// Intersect, mutually common, A and B
class operator Multiply(const aSet: TSet<T>; aValue: T): TSet<T>; overload;
class operator Multiply(const aSet: TSet<T>; const aTArr: TArray<T>): TSet<T>; overload;
class operator Multiply(const aSet1,aSet2 : TSet<T>): TSet<T>; overload;
// Symmetric difference, A xor B = (A+B) - A.Intersect(B)
class operator LogicalXor(const aSet: TSet<T>; aValue: T): TSet<T>; overload;
class operator LogicalXor(const aSet: TSet<T>; aTArr: TArray<T>): TSet<T>; overload;
class operator LogicalXor(const aSet1,aSet2 : TSet<T>): TSet<T>; overload;
//
class operator Equal(const aSet: TSet<T>; aValue: T): Boolean; overload;
class operator Equal(const aSet: TSet<T>; aTArr: TArray<T>): Boolean; overload;
class operator Equal(const aSetLeft,aSetRight: TSet<T>): Boolean; overload;
// SubsetOf (Left <= Right)
class operator LessThanOrEqual(const aSet: TSet<T>; aValue: T): Boolean; overload;
class operator LessThanOrEqual(const aSet: TSet<T>; aTArr: TArray<T>): Boolean; overload;
class operator LessThanOrEqual(const aSetLeft,aSetRight: TSet<T>): Boolean; overload;
// SupersetOf (Left >= Right)
class operator GreaterThanOrEqual(const aSet: TSet<T>; aValue: T): Boolean; overload;
class operator GreaterThanOrEqual(const aSet: TSet<T>; aTArr: TArray<T>): Boolean; overload;
class operator GreaterThanOrEqual(const aSetLeft,aSetRight: TSet<T>): Boolean; overload;
// Set creator
class function Create(const aTArr: array of T; checkDuplicates: Boolean = False): TSet<T>; static;
private
FSetArray : array of T;
FSorted : String; // !! Will be predefined as '' (=False) by compiler.
function GetEmpty: Boolean; inline;
function GetItem(index: Integer): T; inline;
function GetItemCount: Integer; inline;
function GetSorted: Boolean; inline;
procedure SetSorted( sorted: Boolean); inline;
public
// Add
procedure Include(aValue: T); overload;
procedure Include(const aTArr: TArray<T>); overload;
procedure Include(const aTArr: array of T); overload;
procedure Include(const aSet: TSet<T>); overload;
// Subtract; A=[1,2,3]; B=[2,3,4]; B.Exclude(A) = B-A = [4]
procedure Exclude(aValue: T); overload;
procedure Exclude(const aTArr: TArray<T>); overload;
procedure Exclude(const aTArr: array of T); overload;
procedure Exclude(const aSet: TSet<T>); overload;
// Multiply (A and B) A=[1,2,3]; B=[2,3,4]; B.Intersect(A) = B*A = [2,3]
function Intersect(aValue: T): TSet<T>; overload;
function Intersect(const aTArr: TArray<T>): TSet<T>; overload;
function Intersect(const aTArr: array of T): TSet<T>; overload;
function Intersect(const aSet: TSet<T>): TSet<T>; overload;
// A xor B; A=[1,2,3]; B=[2,3,4]; (A+B)-A.Intersect(B) = [1,4]
function SymmetricDiff(aValue: T): TSet<T>; overload;
function SymmetricDiff(const aTArr: TArray<T>): TSet<T>; overload;
function SymmetricDiff(const aTArr: array of T): TSet<T>; overload;
function SymmetricDiff(const aSet: TSet<T>): TSet<T>; overload;
// Identical set
function Equal(aValue: T): Boolean; overload;
function Equal(const aTArr: array of T; checkDuplicates: Boolean = False): Boolean; overload;
function Equal(const aTArr: TArray<T>; checkDuplicates: Boolean = False): Boolean; overload;
function Equal(const aSet: TSet<T>): Boolean; overload;
// Self <= aSet
function SubsetOf(aValue: T): Boolean; overload;
function SubsetOf(const aTArr: array of T; checkDuplicates: Boolean = False): Boolean; overload;
function SubsetOf(const aTArr: TArray<T>; checkDuplicates: Boolean = False): Boolean; overload;
function SubsetOf(const aSet: TSet<T>): Boolean; overload;
// Self >= aSet
function SupersetOf(aValue: T): Boolean; overload;
function SupersetOf(const aTArr: array of T; checkDuplicates: Boolean = False): Boolean; overload;
function SupersetOf(const aTArr: TArray<T>; checkDuplicates: Boolean = False): Boolean; overload;
function SupersetOf(const aSet: TSet<T>): Boolean; overload;
// Is included
function Contains(aValue: T): Boolean; overload;
function Contains(const aTArr: array of T): Boolean; overload;
function Contains(const aTArr: TArray<T>): Boolean; overload;
function Contains(const aSet: TSet<T>): Boolean; overload;
procedure Sort; // QuickSort
function Search( aValue: T): Boolean; // BinarySearch (Set must be sorted)
procedure Clear;
property IsSorted: Boolean read GetSorted;
property IsEmpty: Boolean read GetEmpty;
property Items[index: Integer]: T read GetItem; default;
property ItemCount: Integer read GetItemCount;
end;
implementation
class function TSet<T>.Create(const aTArr: array of T; checkDuplicates: Boolean = False): TSet<T>;
var
i,j,elements : Integer;
duplicate : Boolean;
c : IEqualityComparer<T>;
begin
if checkDuplicates then
begin
c := TEqualityComparer<T>.Default;
// This will remove duplicates
SetLength(Result.FSetArray,Length(aTArr));
elements := 0;
for i := 0 to High(aTArr) do
begin
duplicate := False;
for j := 0 to Pred(elements) do
begin
duplicate := c.Equals(Result.FSetArray[j],aTArr[i]);
if duplicate then
Break;
end;
if not duplicate then
begin
Result.FSetArray[elements] := aTArr[i];
Inc(elements);
end;
end;
SetLength(Result.FSetArray,elements);
end
else
begin
SetLength(Result.FSetArray, Length(aTArr));
for i := 0 to High(aTArr) do
Result.FSetArray[i] := aTArr[i];
end;
end;
class operator TSet<T>.Add(const aSet: TSet<T>; aValue: T): TSet<T>;
begin
Result := aSet;
Result.Include(aValue);
end;
class operator TSet<T>.Add(const aSet: TSet<T>; const aTArr: TArray<T>): TSet<T>;
begin
Result := aSet;
Result.Include(aTArr);
end;
class operator TSet<T>.Add(const aSet1, aSet2: TSet<T>): TSet<T>;
begin
Result := aSet1;
Result.Include(aSet2);
end;
procedure TSet<T>.Include(aValue: T);
begin
if not Contains(aValue) then begin
SetLength(FSetArray,Length(FSetArray)+1);
FSetArray[High(FSetArray)] := aValue;
SetSorted(False);
end;
end;
procedure TSet<T>.Include(const aSet: TSet<T>);
begin
if Self.IsEmpty then
Self := aSet
else
Include(aSet.FSetArray);
end;
procedure TSet<T>.Include(const aTArr: TArray<T>);
var
i : Integer;
begin
for i := 0 to High(aTArr) do
Self.Include(aTArr[i]);
end;
procedure TSet<T>.Include(const aTArr: array of T);
var
i : Integer;
begin
for i := 0 to High(aTArr) do
Self.Include(aTArr[i]);
end;
procedure TSet<T>.Exclude(const aTArr: TArray<T>);
var
i : Integer;
begin
for i := 0 to High(aTArr) do
Exclude(aTArr[i]);
end;
procedure TSet<T>.Exclude(const aTArr: array of T);
var
i : Integer;
begin
for i := 0 to High(aTArr) do
Exclude(aTArr[i]);
end;
procedure TSet<T>.Exclude(const aSet: TSet<T>);
begin
Exclude(aSet.FSetArray);
end;
procedure TSet<T>.Exclude(aValue: T);
var
i : Integer;
c : IEqualityComparer<T>;
begin
c := TEqualityComparer<T>.Default;
for i := 0 to High(FSetArray) do
begin
if c.Equals(FSetArray[i],aValue) then
begin
SetLength(FSetArray,Length(FSetArray)); // Ensure unique dyn array
if (i < High(FSetArray)) then
begin
FSetArray[i] := FSetArray[High(FSetArray)]; // Move last element
Self.SetSorted(False);
end;
SetLength(FSetArray,Length(FSetArray)-1);
Break;
end;
end;
end;
class operator TSet<T>.Subtract(const aSet1, aSet2: TSet<T>): TSet<T>;
begin
Result := aSet1;
Result.Exclude(aSet2.FSetArray);
end;
class operator TSet<T>.Subtract(const aSet: TSet<T>;
const aTArr: TArray<T>): TSet<T>;
begin
Result := aSet;
Result.Exclude(aTArr);
end;
class operator TSet<T>.Subtract(const aSet: TSet<T>; aValue: T): TSet<T>;
begin
Result := aSet;
Result.Exclude(aValue);
end;
class operator TSet<T>.In(aValue: T; const aSet: TSet<T>): Boolean;
begin
Result := aSet.Contains(aValue);
end;
class operator TSet<T>.In(const aTArr: TArray<T>; const aSet: TSet<T>): Boolean;
begin
Result := aSet.Contains(aTArr);
end;
class operator TSet<T>.In(const aSet1: TSet<T>; const aSet2: TSet<T>): Boolean;
begin
Result := aSet2.Contains(aSet1.FSetArray);
end;
function TSet<T>.Contains(aValue: T): Boolean;
var
i : Integer;
c : IEqualityComparer<T>;
begin
if IsSorted then
begin
Result := Search(aValue);
end
else
begin
Result := false;
c := TEqualityComparer<T>.Default;
for i := 0 to High(FSetArray) do
if c.Equals(FSetArray[i],aValue) then
Exit(True);
end;
end;
function TSet<T>.Contains(const aTArr: array of T): Boolean;
var
i: Integer;
begin
Result := High(aTArr) >= 0;
for i := 0 to High(aTArr) do
begin
if IsSorted then
Result := Search(aTArr[i])
else
Result := Contains(aTArr[i]);
if not Result then
Exit(false);
end;
end;
function TSet<T>.Contains(const aTArr: TArray<T>): Boolean;
var
i : Integer;
begin
Result := High(aTArr) >= 0;
for i := 0 to High(aTArr) do
begin
if IsSorted then
Result := Search(aTArr[i])
else
Result := Contains(aTArr[i]);
if not Result then
Exit(false);
end;
end;
function TSet<T>.Contains(const aSet: TSet<T>): Boolean;
begin
Result := Contains(aSet.FSetArray);
end;
function TSet<T>.GetEmpty: Boolean;
begin
Result := (Self.ItemCount = 0);
end;
function TSet<T>.GetItem(index: Integer): T;
begin
Result := Self.FSetArray[index];
end;
function TSet<T>.GetItemCount: Integer;
begin
Result := Length(Self.FSetArray);
end;
procedure TSet<T>.Clear;
begin
SetLength(FSetArray,0);
Self.SetSorted(False);
end;
// Get the mutually common elements, aka the intersect.
class operator TSet<T>.Multiply(const aSet: TSet<T>; aValue: T): TSet<T>;
begin
Result:= aSet.Intersect(aValue);
end;
class operator TSet<T>.Multiply(const aSet: TSet<T>; const aTArr: TArray<T>): TSet<T>;
begin
Result:= aSet.Intersect(aTArr);
end;
class operator TSet<T>.Multiply(const aSet1,aSet2: TSet<T>): TSet<T>;
begin
Result := aSet1.Intersect(aSet2);
end;
function TSet<T>.Intersect(aValue : T): TSet<T>;
var
i : Integer;
begin
if Self.Contains(aValue) then
Result.Include(aValue)
else
Result.Clear;
Result.SetSorted(Result.ItemCount = 1);
end;
function TSet<T>.Intersect(const aSet: TSet<T>): TSet<T>;
var
i,items : Integer;
begin
SetLength(Result.FSetArray,aSet.ItemCount);
items := 0;
for i := 0 to High(aSet.FSetArray) do
begin
if Self.Contains(aSet.FSetArray[i]) then
begin
Result.FSetArray[items] := aSet.FSetArray[i];
Inc(items);
end;
end;
SetLength(Result.FSetArray,items);
Result.SetSorted(Self.IsSorted and aSet.IsSorted);
end;
function TSet<T>.Intersect(const aTArr: array of T): TSet<T>;
var
i : Integer;
begin
for i := 0 to High(aTArr) do
begin
if Self.Contains(aTArr[i]) then
Result.Include(aTArr[i]);
end;
Result.SetSorted(False);
end;
function TSet<T>.Intersect(const aTArr: TArray<T>): TSet<T>;
var
i : Integer;
begin
for i := 0 to High(aTArr) do
begin
if Self.Contains(aTArr[i]) then
Result.Include(aTArr[i]);
end;
Result.SetSorted(False);
end;
//
function TSet<T>.Equal(aValue: T): Boolean;
begin
Result := (Self.ItemCount = 1) and Self.Contains(aValue);
end;
function TSet<T>.Equal(const aTArr: array of T; checkDuplicates: Boolean = False): Boolean;
begin
if checkDuplicates then
Result :=
(Self.ItemCount <= Length(aTArr)) and
Self.Equal(TSet<T>.Create(aTArr,True)) // Remove possible duplicates
else
Result :=
(Self.ItemCount = Length(aTArr)) and
Self.Contains(aTArr);
end;
function TSet<T>.Equal(const aTArr: TArray<T>; checkDuplicates: Boolean = False): Boolean;
begin
if checkDuplicates then
Result :=
(Self.ItemCount <= Length(aTArr)) and
Self.Equal(TSet<T>.Create(aTArr,True)) // Remove possible duplicates
else
Result :=
(Self.ItemCount = Length(aTArr)) and
Self.Contains(aTArr);
end;
function TSet<T>.Equal(const aSet: TSet<T>): Boolean;
begin
Result :=
(Self.ItemCount = aSet.ItemCount) and
Contains(aSet);
end;
class operator TSet<T>.Equal(const aSet: TSet<T>; aValue: T): Boolean;
begin
Result := aSet.Equal(aValue);
end;
class operator TSet<T>.Equal(const aSet: TSet<T>; aTArr: TArray<T>): Boolean;
begin
Result := aSet.Equal(aTArr,True);
end;
class operator TSet<T>.Equal(const aSetLeft,aSetRight: TSet<T>): Boolean;
begin
Result := aSetLeft.Equal(aSetRight);
end;
// Self <= aSet
function TSet<T>.SubsetOf(aValue: T): Boolean;
begin
Result := (Self.ItemCount = 1) and Self.Equal(aValue);
end;
function TSet<T>.SubsetOf(const aTArr: array of T; checkDuplicates: Boolean = False): Boolean;
begin
Result := Self.SubsetOf(TSet<T>.Create(aTArr,checkDuplicates));
end;
function TSet<T>.SubsetOf(const aTArr: TArray<T>; checkDuplicates: Boolean = False): Boolean;
begin
Result := SubsetOf(TSet<T>.Create(aTArr,checkDuplicates));
end;
function TSet<T>.SubsetOf(const aSet: TSet<T>): Boolean;
begin
Result :=
(Self.ItemCount <= aSet.ItemCount) and
aSet.Contains(Self);
end;
// SubsetOf (Left <= Right)
class operator TSet<T>.LessThanOrEqual(const aSet: TSet<T>; aValue: T): Boolean;
begin
Result := aSet.SubsetOf(aValue);
end;
class operator TSet<T>.LessThanOrEqual(const aSet: TSet<T>; aTArr: TArray<T>): Boolean;
begin
Result := aSet.SubsetOf(aTArr,True);
end;
class operator TSet<T>.LessThanOrEqual(const aSetLeft,aSetRight: TSet<T>): Boolean;
begin
Result := aSetLeft.SubsetOf(aSetRight);
end;
// Self >= aSet
function TSet<T>.SupersetOf(const aSet: TSet<T>): Boolean;
begin
Result :=
(Self.ItemCount >= aSet.ItemCount) and
Self.Contains(aSet);
end;
function TSet<T>.SupersetOf(aValue: T): Boolean;
begin
Result := (Self.ItemCount >= 1) and Self.Contains(aValue);
end;
function TSet<T>.SupersetOf(const aTArr: array of T; checkDuplicates: Boolean = False): Boolean;
begin
Result := SupersetOf(TSet<T>.Create(aTArr,checkDuplicates));
end;
function TSet<T>.SupersetOf(const aTArr: TArray<T>; checkDuplicates: Boolean = False): Boolean;
begin
Result := SupersetOf(TSet<T>.Create(aTArr,checkDuplicates));
end;
// SupersetOf (Left >= Right)
class operator TSet<T>.GreaterThanOrEqual(const aSet: TSet<T>; aValue: T): Boolean;
begin
Result := aSet.SupersetOf(aValue);
end;
class operator TSet<T>.GreaterThanOrEqual(const aSet: TSet<T>; aTArr: TArray<T>): Boolean;
begin
Result := aSet.SupersetOf(aTArr,True);
end;
class operator TSet<T>.GreaterThanOrEqual(const aSetLeft,aSetRight: TSet<T>): Boolean;
begin
Result := aSetLeft.SupersetOf(aSetRight);
end;
// A xor B; A=[1,2,3]; B=[2,3,4]; (A+B)-A.Intersect(B) = [1,4] alt:
function TSet<T>.SymmetricDiff(aValue: T): TSet<T>;
begin
Result := Self;
Result.Include(aValue);
Result.Exclude(Self.Intersect(aValue));
Result.SetSorted(False);
end;
function TSet<T>.SymmetricDiff(const aTArr: TArray<T>): TSet<T>;
begin
Result := Self;
Result.Include(aTArr);
Result.Exclude(Self.Intersect(aTArr));
Result.SetSorted(False);
end;
function TSet<T>.SymmetricDiff(const aTArr: array of T): TSet<T>;
begin
Result := Self;
Result.Include(aTArr);
Result.Exclude(Self.Intersect(aTArr));
Result.SetSorted(False);
end;
function TSet<T>.SymmetricDiff(const aSet: TSet<T>): TSet<T>;
begin
Result:= Self;
Result.Include(aSet);
Result.Exclude(Self.Intersect(aSet));
Result.SetSorted(False);
end;
class operator TSet<T>.LogicalXor(const aSet: TSet<T>; aValue: T): TSet<T>;
begin
Result := aSet.SymmetricDiff(aValue);
end;
class operator TSet<T>.LogicalXor(const aSet: TSet<T>; aTArr: TArray<T>): TSet<T>;
begin
Result := aSet.SymmetricDiff(aTArr);
end;
class operator TSet<T>.LogicalXor(const aSet1,aSet2 : TSet<T>): TSet<T>;
begin
Result := aSet1.SymmetricDiff(aSet2);
end;
procedure TSet<T>.Sort;
begin
SetLength(Self.FSetArray,Length(Self.FSetArray)); // Ensure COW
TArray.Sort<T>(Self.FSetArray);
SetSorted(True);
end;
function TSet<T>.Search(aValue: T): Boolean;
var
Index: Integer;
begin
Result := TArray.BinarySearch<T>(Self.FSetArray,aValue,Index);
end;
function TSet<T>.GetSorted: Boolean;
begin
Result := (FSorted = '1');
end;
procedure TSet<T>.SetSorted(sorted: Boolean);
begin
if sorted then
FSorted := '1'
else
FSorted := '0';
end;
end.
基准:
program ProjectGenericSet;
{$APPTYPE CONSOLE}
uses
System.Diagnostics,
System.Generics.Defaults,
System.Generics.Collections,
GenericSet in 'GenericSet.pas';
var
set1,set2,set3 : TSet<Word>;
sw : TStopWatch;
ok : Boolean;
i,j,max: Integer;
begin
Randomize;
max := $10000;
// Populate a sample set with 32K items.
repeat
set1.Include(Random(max));
until (set1.ItemCount = (max DIV 2));
// Populate a test set with items in sample set
repeat
set2.Include(set1[Random(max DIV 2)]);
until (set2.ItemCount = 100);
WriteLn('Test in Sample (unsorted), 1.000 iterations...');
sw := TStopWatch.StartNew;
for i := 1 TO 1000 DO
ok := set1.Contains(set2);
sw.Stop;
WriteLn('Result:',ok,' ',sw.ElapsedMilliseconds,' [ms]');
set1.Sort; // Sort
WriteLn('Test in Sample (sorted), 200.000 iterations...');
sw := TStopWatch.StartNew;
for i := 1 TO 200000 DO
begin
ok := set1.Contains(set2);
end;
sw.Stop;
WriteLn('Result:',ok,' ',sw.ElapsedMilliseconds,' [ms]');
WriteLn('Test*Test (unsorted), 200.000 iterations...');
sw := TStopWatch.StartNew;
for i := 1 TO 200000 DO
begin
set3 := set2.Intersect(set2);
end;
sw.Stop;
WriteLn('Result:',set3=set2,' ',sw.ElapsedMilliseconds,' [ms]');
set2.Sort;
WriteLn('Test*Test (sorted), 200.000 iterations...');
sw := TStopWatch.StartNew;
for i := 1 TO 200000 DO
begin
set3 := set2.Intersect(set2);
end;
sw.Stop;
WriteLn('Result:',set3=set2,' ',sw.ElapsedMilliseconds,' [ms]');
ReadLn;
end.
关于arrays - 查找两个数组中的公共(public)元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19466038/
在 C 中: int a[10]; printf("%p\n", a); printf("%p\n", &a[0]); 产量: 0x7fff5606c600 0x7fff5606c600 这是我所期望
我一直在尝试运行此循环来更改基于数组的元素的位置,但出现以下错误。不太确定哪里出了问题。任何想法或想法!谢谢。 var population = [[98, 8, 45, 34, 56], [9, 1
我正在尝试获取一个 Ruby 数组数组并将其分组以计算其值。 数组有一个月份和一个 bool 值: array = [["June", false], ["June", false], ["June"
所以我们的目标是在遇到某个元素时将数组分割成子数组下面的示例 array.split("stop here") ["haii", "keep", "these in the same array bu
在this问题已经回答了两个表达式是相等的,但在这种情况下它们会产生不同的结果。对于给定的 int[] 分数,为什么会这样: Arrays.stream(scores) .forEac
我认为我需要的是哈希数组的数组,但我不知道如何制作它。 Perl 能做到吗? 如果是这样,代码会是什么样子? 最佳答案 perldoc perldsc是了解 Perl 数据结构的好文档。 关于arra
我遇到了这个问题,从 API 中我得到一个扩展 JSON,其中包含一个名为坐标的对象,该对象是一个包含数组 o 数组的数组。 为了更清楚地看这个例子: "coordinates": [
postgres 中有(v 9.5,如果重要的话): create table json_test( id varchar NOT NULL, data jsonb NOT NULL, PRIM
我用 echo "${array[@]}" 和 echo "${array[*]}" 得到了相同的结果。 如果我这样做: mkdir 假音乐; touch fakemusic/{Beatles,Sto
我正在尝试创建 typealias 对象的数组数组 - 但我收到“表达式类型不明确,没有更多上下文”编译错误。这是我的代码: typealias TestClosure = ((message: St
如果您在 Python 中创建一维数组,使用 NumPy 包有什么好处吗? 最佳答案 这完全取决于您打算如何处理数组。如果您所做的只是创建简单数据类型的数组并进行 I/O,array模块就可以了。 另
当我将数组推送到只有一个数组作为其唯一元素的数组数组时,为什么会得到这种数据结构? use v6; my @d = ( [ 1 .. 3 ] ); @d.push( [ 4 .. 6 ] ); @d.
在 Julia 中,我想将定义为二维数组向量的数据转换为二维矩阵数组。 如下例所述,我想把数据s转换成数据t,但是至今没有成功。 我该如何处理这个案子? julia> s = [[1 2 3], [4
C 没有elementsof 关键字来获取数组的元素数。所以这通常由计算 sizeof(Array)/sizeof(Array[0]) 代替但这需要重复数组变量名。1[&Array] 是指向数组后第一
所以,假设我有一个像这样的(愚蠢的)函数: function doSomething(input: number|string): boolean { if (input === 42 || in
我有以下数组: a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] 我将它用于一些像这样的视觉内容: 1 2 3 4 5 6 7 8 9 10
我想知道数组中的 .toList 与 .to[List] 之间有什么区别。我在spark-shell中做了这个测试,结果没有区别,但我不知道用什么更好。任何意见? scala> val l = Arr
我很难获得完全相同对象的多个元素的当前元素索引: $b = "A","D","B","D","C","E","D","F" $b | ? { $_ -contains "D" } 替代版本: $b =
我正在尝试使用来自我的 API 的 v-select 执行 options,我将数据放在数组数组中。 Array which I got from API 它应该是一个带有搜索的 select,因为它
这个问题在这里已经有了答案: String literals: pointer vs. char array (1 个回答) 4 个月前关闭。 当我执行下一个代码时 int main() {
我是一名优秀的程序员,十分优秀!