# Path: replacement_policies/SubsetCache.py
# class SubsetCache(Cache):
#     def __init__(self, size, **args):
#         #It only caches content from certain users
#         Cache.__init__(self, size)
#         assert size > 0
#         self._store = pylru.lrucache(size)
#         self.max_size = size
#         self.subset = args['subset']
#         self.prog = re.compile('\/friend([0-9]*)\/')
#     def accept(self, content_name):
#         res = self.prog.match(content_name)
#         return res != None and self.subset.has_key(res.group(1))


from replacement_policies.SubsetCache import SubsetCache
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Library General Public License for more details.
#
#You should have received a copy of the GNU Library General Public
#License along with this library; if not, write to the
#Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
#Boston, MA  02110-1301, USA. 
#
#####################################################################

class CommunitySubsetCache(SubsetCache):
    #Only accept content from the same community
    def __init__(self, size, **args):
        
        social_users_in_node = args['users']

        nodes_ = {}
        
        comu = []
        for n in social_users_in_node:
            comu.append(args['partition'][int(n)])

        #We get all the users in the same community
        for k,v in args['partition'].items():
            if v in comu:
                nodes_[str(k)] = k


# Path: replacement_policies/SubsetCache.py
# class SubsetCache(Cache):
#     def __init__(self, size, **args):
#         #It only caches content from certain users
#         Cache.__init__(self, size)
#         assert size > 0
#         self._store = pylru.lrucache(size)
#         self.max_size = size
#         self.subset = args['subset']
#         self.prog = re.compile('\/friend([0-9]*)\/')
#     def accept(self, content_name):
#         res = self.prog.match(content_name)
#         return res != None and self.subset.has_key(res.group(1))


# Path: replacement_policies/CommunitySubsetCache.py
from replacement_policies.SubsetCache import SubsetCache

#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Library General Public License for more details.
#
#You should have received a copy of the GNU Library General Public
#License along with this library; if not, write to the
#Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
#Boston, MA  02110-1301, USA. 
#
#####################################################################

class CommunitySubsetCache(SubsetCache):
    #Only accept content from the same community
    def __init__(self, size, **args):
        
        social_users_in_node = args['users']

        nodes_ = {}
        
        comu = []
        for n in social_users_in_node:
            comu.append(args['partition'][int(n)])

        #We get all the users in the same community
        for k,v in args['partition'].items():
            if v in comu:
                nodes_[str(k)] = k


        SubsetCache.__init__(self, size, subset=nodes_)