Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WCCL
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Analysers
WCCL
Commits
48482b29
Commit
48482b29
authored
13 years ago
by
Bartosz Broda
Browse files
Options
Downloads
Patches
Plain Diff
fix set intersect with Tomek
parent
39d553cc
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libwccl/ops/functions/setops.h
+35
-17
35 additions, 17 deletions
libwccl/ops/functions/setops.h
tests/data/setops.ccl
+10
-0
10 additions, 0 deletions
tests/data/setops.ccl
with
45 additions
and
17 deletions
libwccl/ops/functions/setops.h
+
35
−
17
View file @
48482b29
...
...
@@ -6,6 +6,7 @@
#include
<libwccl/values/strset.h>
namespace
Wccl
{
typedef
boost
::
shared_ptr
<
StrSet
>
StrSetPtr
;
template
<
class
T
>
class
SetListOperator
:
public
ListOperator
<
T
>
...
...
@@ -84,12 +85,9 @@ FunctionBase::BaseRetValPtr SetUnion<StrSet>::apply_internal(const FunExecContex
boost
::
shared_ptr
<
StrSet
>
out
=
boost
::
make_shared
<
StrSet
>
();
if
(
expressions_
->
empty
())
return
out
;
const
boost
::
shared_ptr
<
const
StrSet
>&
set1
=
(
*
expressions_
)[
0
]
->
apply
(
context
);
const
boost
::
shared_ptr
<
const
StrSet
>&
set2
=
(
*
expressions_
)[
1
]
->
apply
(
context
);
std
::
set_union
(
set1
->
contents
().
begin
(),
set1
->
contents
().
end
(),
set2
->
contents
().
begin
(),
set2
->
contents
().
end
(),
std
::
inserter
(
out
->
contents
(),
out
->
contents
().
begin
()));
out
->
contents
()
=
set1
->
contents
();
for
(
size_t
i
=
2
;
i
<
expressions_
->
size
();
++
i
)
{
for
(
size_t
i
=
1
;
i
<
expressions_
->
size
();
++
i
)
{
const
boost
::
shared_ptr
<
const
StrSet
>&
seti
=
(
*
expressions_
)[
i
]
->
apply
(
context
);
foreach
(
const
UnicodeString
&
s
,
seti
->
contents
())
{
out
->
insert
(
s
);
...
...
@@ -116,20 +114,40 @@ FunctionBase::BaseRetValPtr SetIntersection<StrSet>::apply_internal(const FunExe
if
(
expressions_
->
size
()
==
1
)
return
expressions_
->
front
()
->
apply
(
context
);
boost
::
shared_ptr
<
StrSet
>
out
=
boost
::
make_shared
<
StrSet
>
();
if
(
expressions_
->
empty
())
return
out
;
const
boost
::
shared_ptr
<
const
StrSet
>&
set1
=
(
*
expressions_
)[
0
]
->
apply
(
context
);
const
boost
::
shared_ptr
<
const
StrSet
>&
set2
=
(
*
expressions_
)[
1
]
->
apply
(
context
);
std
::
set_intersection
(
set1
->
contents
().
begin
(),
set1
->
contents
().
end
(),
set2
->
contents
().
begin
(),
set2
->
contents
().
end
(),
std
::
inserter
(
out
->
contents
(),
out
->
contents
().
begin
()));
for
(
size_t
i
=
2
;
i
<
expressions_
->
size
();
++
i
)
{
boost
::
shared_ptr
<
StrSet
>
out2
=
boost
::
make_shared
<
StrSet
>
();
const
boost
::
shared_ptr
<
const
StrSet
>&
seti
=
(
*
expressions_
)[
i
]
->
apply
(
context
);
std
::
set_intersection
(
seti
->
contents
().
begin
(),
seti
->
contents
().
end
(),
out
->
contents
().
begin
(),
out
->
contents
().
end
(),
std
::
inserter
(
out
->
contents
(),
out2
->
contents
().
begin
()));
out
->
contents
().
swap
(
out2
->
contents
());
//find smallest set
size_t
smallest
=
0
;
size_t
smallest_size
=
(
std
::
numeric_limits
<
size_t
>::
max
)();
for
(
size_t
i
=
0
;
i
<
expressions_
->
size
();
++
i
)
{
const
boost
::
shared_ptr
<
const
StrSet
>&
set1
=
(
*
expressions_
)[
i
]
->
apply
(
context
);
size_t
ssize
=
set1
->
size
();
if
(
ssize
<
smallest_size
){
smallest
=
i
;
smallest_size
=
ssize
;
}
}
const
boost
::
shared_ptr
<
const
StrSet
>&
smallest_set
=
(
*
expressions_
)[
smallest
]
->
apply
(
context
);
//for each element in smallest set
foreach
(
const
UnicodeString
&
s
,
smallest_set
->
contents
())
{
bool
everywhere
=
true
;
// find if every other set contains this element
for
(
size_t
i
=
0
;
i
<
expressions_
->
size
()
&&
everywhere
;
++
i
)
{
if
(
i
==
smallest
)
continue
;
const
boost
::
shared_ptr
<
const
StrSet
>&
set1
=
(
*
expressions_
)[
i
]
->
apply
(
context
);
if
(
set1
->
contents
().
find
(
s
)
==
set1
->
contents
().
end
())
everywhere
=
false
;
}
if
(
everywhere
)
out
->
insert
(
s
);
}
return
out
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/data/setops.ccl
0 → 100644
+
10
−
0
View file @
48482b29
---
intersection(["ala","ma","kota"], ["kota", "kij"])
["kota"]
---
inter(union(["ala","ma","kota"], ["kota", "kij"]), ["ala", "ma", "kota", "kij"])
True
---
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment