summaryrefslogtreecommitdiff
path: root/src/users.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-09 10:04:58 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-08-09 10:04:58 +0000
commite964e2286d78ab691078db40e402f685561ef0ca (patch)
tree867b2a013238ef4aa0d4757ce949b15ad84f1393 /src/users.cpp
parentd91d734257619e26918b4da8153af42cd4f316de (diff)
common_channels -> userrec::SharesChannelWith()
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4805 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/users.cpp')
-rw-r--r--src/users.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/users.cpp b/src/users.cpp
index 5086bd093..929caf19c 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1564,3 +1564,37 @@ void userrec::WriteWallOps(const char* text, ...)
this->WriteWallOps(std::string(textbuffer));
}
+/* return 0 or 1 depending if users u and u2 share one or more common channels
+ * (used by QUIT, NICK etc which arent channel specific notices)
+ *
+ * The old algorithm in 1.0 for this was relatively inefficient, iterating over
+ * the first users channels then the second users channels within the outer loop,
+ * therefore it was a maximum of x*y iterations (upon returning 0 and checking
+ * all possible iterations). However this new function instead checks against the
+ * channel's userlist in the inner loop which is a std::map<userrec*,userrec*>
+ * and saves us time as we already know what pointer value we are after.
+ * Don't quote me on the maths as i am not a mathematician or computer scientist,
+ * but i believe this algorithm is now x+(log y) maximum iterations instead.
+ */
+bool userrec::SharesChannelWith(userrec *other)
+{
+ if ((!other) || (this->registered != REG_ALL) || (other->registered != REG_ALL))
+ return false;
+
+ /* Outer loop */
+ for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+ {
+ /* Fetch the channel from the user */
+ ucrec* user_channel = *i;
+
+ if (user_channel->channel)
+ {
+ /* Eliminate the inner loop (which used to be ~equal in size to the outer loop)
+ * by replacing it with a map::find which *should* be more efficient
+ */
+ if (user_channel->channel->HasUser(other))
+ return true;
+ }
+ }
+ return false;
+}