Diff

mod_anti_spam/trie.lib.lua @ 6192:76ae646563ea

Backed out changeset 94399ad6b5ab Unintentional committed changes
author Matthew Wild <mwild1@gmail.com>
date Thu, 06 Feb 2025 10:23:08 +0000
parent 6191:94399ad6b5ab
child 6211:750d64c47ec6
line wrap: on
line diff
--- a/mod_anti_spam/trie.lib.lua	Thu Feb 06 10:13:39 2025 +0000
+++ b/mod_anti_spam/trie.lib.lua	Thu Feb 06 10:23:08 2025 +0000
@@ -120,29 +120,6 @@
 	end
 end
 
-local function find_match_in_descendents(node, item, len, i)
-	for child_byte, child_node in pairs(node) do
-		if type(child_byte) == "number" then
-			if child_node.terminal then
-				local bits = child_node.value;
-				for j = #bits, 1, -1 do
-					local b = bits[j]-((i-1)*8);
-					if b ~= 8 then
-						local mask = bit.bnot(2^b-1);
-						if bit.band(bit.bxor(c, child_byte), mask) == 0 then
-							return true;
-						end
-					end
-				end
-			else
-				
-			end
-		end
-	end
-	return false;
-end
-
---
 function trie_methods:contains_ip(item)
 	item = item.packed;
 	local node = self.root;
@@ -155,57 +132,25 @@
 		local c = item:byte(i);
 		local child = node[c];
 		if not child then
-			return find_match_in_descendents(node, item, len, i);
+			for child_byte, child_node in pairs(node) do
+				if type(child_byte) == "number" and child_node.terminal then
+					local bits = child_node.value;
+					for j = #bits, 1, -1 do
+						local b = bits[j]-((i-1)*8);
+						if b ~= 8 then
+							local mask = bit.bnot(2^b-1);
+							if bit.band(bit.bxor(c, child_byte), mask) == 0 then
+								return true;
+							end
+						end
+					end
+				end
+			end
+			return false;
 		end
 		node = child;
 	end
 end
---]]
-
---[[
-function trie_methods:contains_ip(item)
-	item = item.packed
-	local node = self.root
-	local len = #item
-
-	print(string.byte(item, 1, 4))
-
-	local function search(node, index)
-		if node.terminal then
-			print("S", "TERM")
-			return true
-		end
-
-		if index > len then
-			print("S", "MAX LEN")
-			return false
-		end
-
-		local c = item:byte(index)
-		local child = node[c]
-
-		print("S", (" "):rep(index), ("item[%d] = %d, has_child = %s"):format(index, c, not not child));
-
-		if child then
-			-- Continue searching down the current path
-			return search(child, index + 1)
-		else
-			-- Check all children for a terminal node
-			for child_byte, child_node in pairs(node) do
-				if type(child_byte) == "number" and child_byte then
-					if search(child_node, index + 1) then
-						return true
-					end
-				end
-			end
-		end
-
-		return false
-	end
-
-	return search(node, 1)
-end
---]]
 
 local function new()
 	return setmetatable({