-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge same speaker overlapping turns
- Loading branch information
Showing
4 changed files
with
162 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright (C) 2014 Łukasz Czerwiński | ||
* | ||
* GitHub: https://github.com/wo3kie/groupBy | ||
* | ||
* Distributed under the BSD Software License (see file license) | ||
*/ | ||
|
||
#ifndef SPYDER_GROUP_BY_H | ||
#define SPYDER_GROUP_BY_H | ||
|
||
#include <map> | ||
#include <vector> | ||
|
||
namespace spyder | ||
{ | ||
/* | ||
* return_type | ||
*/ | ||
|
||
template< typename T > | ||
struct return_type | ||
{ | ||
typedef typename return_type< typename std::decay< decltype( &T::operator() )>::type >::type type; | ||
}; | ||
|
||
template< typename R, typename C, typename... A > | ||
struct return_type< R ( C::* )( A... ) > | ||
{ | ||
typedef typename std::decay< R >::type type; | ||
}; | ||
|
||
template< typename R, typename C, typename... A > | ||
struct return_type< R ( C::* )( A... ) const > | ||
{ | ||
typedef typename std::decay< R >::type type; | ||
}; | ||
|
||
template< typename R, typename... A > | ||
struct return_type< R ( * )( A... ) > | ||
{ | ||
typedef typename std::decay< R >::type type; | ||
}; | ||
} | ||
|
||
namespace spyder | ||
{ | ||
/* | ||
* GroupBy | ||
*/ | ||
|
||
template< typename Arg, typename... Ts > | ||
struct GroupBy; | ||
|
||
template< typename Arg, typename T, typename... Ts > | ||
struct GroupBy< Arg, T, Ts... > | ||
{ | ||
typedef std::map< | ||
typename spyder::return_type< typename std::decay< T >::type >::type, | ||
typename GroupBy< Arg, Ts... >::return_type | ||
> return_type; | ||
}; | ||
|
||
template< typename Arg, typename T > | ||
struct GroupBy< Arg, T > | ||
{ | ||
typedef std::map< | ||
typename return_type< typename std::decay< T >::type >::type, | ||
std::vector< Arg > | ||
> return_type; | ||
}; | ||
} | ||
|
||
namespace spyder | ||
{ | ||
/* | ||
* groupByImpl | ||
*/ | ||
|
||
template< typename Map, typename Iterator, typename F > | ||
void groupByImpl( Map & map, Iterator && current, F && f ) | ||
{ | ||
map[ f( *current ) ].push_back( *current ); | ||
} | ||
|
||
template< typename Map, typename Iterator, typename F, typename... Fs > | ||
void groupByImpl( Map & map, Iterator && current, F && f, Fs &&... fs ) | ||
{ | ||
groupByImpl( map[ f( *current ) ], current, std::forward< Fs >( fs )... ); | ||
} | ||
} | ||
|
||
/* | ||
* groupBy | ||
*/ | ||
|
||
template< typename Iterator, typename F, typename... Fs > | ||
typename spyder::GroupBy< typename std::iterator_traits< Iterator >::value_type, F, Fs... >::return_type | ||
groupBy( Iterator begin, Iterator const end, F && f, Fs &&... fs ) | ||
{ | ||
typename spyder::GroupBy< typename std::iterator_traits< Iterator >::value_type, F, Fs... >::return_type result; | ||
for( /* empty */ ; begin != end ; ++ begin ) | ||
{ | ||
spyder::groupByImpl( result, begin, std::forward< F >( f ), std::forward< Fs >( fs )... ); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters